Tech Support banner

Status
Not open for further replies.
1 - 8 of 8 Posts

·
Registered
Joined
·
26 Posts
Discussion Starter #1
Hi,

just wondering how one would allow users to download a file only after they have authenticated through a login page using PHP.

For example:
Say I have a file file.exe which only those with a password and username can have access to; and this file is located at http://www.mysite.com/progs/file.exe. So members login to the page via their username and password and then a page appears with a link to the file. After hitting the link, they get the file.
I already know how to do all of the above in PHP, however the problem arises when someone enters the following in their browser; http://www.mysite.com/progs/file.exe and they get access to the file without having to go through the login page first.

Anyone have a solution or work-around to this problem.
 

·
Registered
Joined
·
1,097 Posts
If you are using Apache, it would probably be better to use .htpasswd. You could protect your entire web folder or individual files.
 

·
Registered
Joined
·
26 Posts
Discussion Starter #3
Resolution,

first and foremost thanks for the quick response.

I got the webpage up and running using the .htaccess files. I always wondered how websites used this particular type of authentication; I guess now I know.

It's very effective, but I actual had some trouble setting it up. The main (and really only) problem with using .htaccess file was the fact that you needed to know the full pathname of the .htpasswd (or file which contains the encrypted passwords). Since I'm not actually hosting the website on my machine, getting the full pathname of the page on the server hosting the website was the difficult part. Is there a way to actually get around this problem. This is the only issue I have about using .htaccess file; other than this, they're perfect. I tried playing around with how you specify the path in the file (including using the relative path to the file), but it only seems to like the full pathnames.
 

·
TSF Team Emeritus
Joined
·
337 Posts

·
Registered
Joined
·
26 Posts
Discussion Starter #5
E-Liam,

Thanks for the link. I was actually trying something similar by writing a PHP script which did this. I soon realized that my ISP's servers don't support cgi scripts and this is where the website is being hosted. Maybe the only solution might be to pay for web hosting, where my site would be hosted on decent servers where you won't be so restricted. :smile:

It would still be really good if there was a way to get around what seems to be a really minor issue, but I can't image how you would actually go about it other than accessing the machine where the website is hosted.

On another note in regards to .htaccess files:
Is there a way to limit the number of retries the user gets when they enter in an incorrect password. On most sites which use .htaccess files, you only get like 3 tries before your redirected to another page warning you that your username/password was incorrect. By default, whenever I enter an incorrect password the authentication box just keep re-appearing until I hit cancel. It would be better if you could actually tell the user explicitly that they're entering in an incorrect password or username, since the current behaviour is also similar to when the .htaccess file can't find the .htpasswd file to authenticate the user. Therefore, it appears as if your .htaccess file is broken, rather than the username and password entered being incorrect.
 

·
Registered
Joined
·
1 Posts
After couple of hours of reading on .htaccess for apache in windows - I finally figured out - You need to set the open_basedir directive in your php.ini file to restrict access to file system beyond the web folder. Considering it took my good amount of searching I added couple of articles on PHP security that applies for windows here:

http://oviya.me
 

·
Registered
Joined
·
1 Posts
Hello,

I've read in another forum that a solution to this problem is to stor the files in a directory above the www directory. Therefore the users browser is unable to get to the page, but the PHP scripts can be pointed to it.

Is this a suitable solution and what are the drawbacks of using this method?
How would using .htaccess compare?

Thanks
 

·
Registered
Joined
·
409 Posts
How much PHP do you know? If you are just wondering how you can protect a PDF or MP3 file or something, you can have the server parse PHP in specific filetypes, but it requires access to the .htaccess file again. Can you do that or not?

Do you need someone to write the PHP for you or are you set with that?
 
1 - 8 of 8 Posts
Status
Not open for further replies.
Top