Password Protect Files

absolutpowers

New member
Joined
Mar 16, 2008
Messages
2
Hi

I want to learn how to password protect individual files within a folder.

I know how to password protect folders, however, even if I protect folders, i can download a file within that folder if i have the correct path without entering the password.

I want to set it up such that, when i give a client a link to his file, it promts for a username and password that i set for that file. Once the client enters correct information it lets them view or download the file.

Right now i can change persmissions on individual file to restrict access, but not passwrod protect like you can with the folder.

Any help is appreciated.

Thanks
 
however, even if I protect folders, i can download a file within that folder if i have the correct path without entering the password.

Not if password protection is set up correctly. That is the whole point of it.

Password protecting the folder means to access all the files in the folder you have to enter the username and password. Likely you have already enter the username and password and did not close all your browser windows before doing the test.
 
Hi there absolutpowers!

What you want to do is done very easily using Apache's .htaccess files. In the same directory where you would like to protect the individual file, create an .htaccess file with the following contents...

<Files secure.php>
AuthType Basic
AuthName "Prompt"
AuthUserFile /home/path/.htpasswd
Require valid-user
</Files>

NOTES:
1) The secure.php file is the one that will be protected.
2) Change the location of the 'AuthUserFile' setting so that it points to your .htpasswd file. The .htpasswd file contains the username and password of the allowed users, for example: user1:cws1AriKSqZfU (the username and password is user1)

That should work...
 
absolutpowers is under the misconception that the files can still be accessed even if the folder they are in is password protected. That is simply not true.

He does NOT have to protect individual files if the entire folder is password protected. If he wanted to password protect some files and not some other files within the same folder then the above would be correct and he would have to eliminate password protection on the folder.

He made the statement:
even if I protect folders, i can download a file within that folder if i have the correct path without entering the password.

That is simply not true.
 
floyd, and czotos Thanks!

When i protect folders, it does ask me for the password once, however, it wont the next time i try downloading the files, perhaps i need to clear my cache or something...

I wanted individual files within a folder to have their unique protection and ask for the password everytime. I guess for that i will have to use the Apache's .htaccess files and see how it works

unless there is another way.

I apologize for the trouble, I am very raw to file hosting...

Thanks again...
 
When i protect folders, it does ask me for the password once, however, it wont the next time i try downloading the files

That is correct. You only have to enter the password once to download all the files in that folder. To prompt for the password again all the browser windows have to be closed and reopened. See my first post.

I wanted individual files within a folder to have their unique protection and ask for the password everytime.

Then yes you will have to use what czotos posted. I have not tested that technique so I cannot confirm or deny how it works. It looks good though. You will have to enter <Files> tag for each file in .htaccess. Seems like a lot of trouble though.
 
If you would like to secure/protect multiple files, then use this in your .htaccess file...

<FilesMatch "^(execute|index|secure|insanity|biscuit)*$">
AuthType basic
AuthName "Prompt"
AuthUserFile /home/path/.htpasswd
Require valid-user
</FilesMatch>
 
Back
Top