Skip to content
WJunction - Webmaster Forum

password protect a single file ?

Status
Not open for further replies.
I want to make a text file (located under /home/public_html) to be viewable through a browser by me only.
One way is to make it password protected, I know how to do this through cpanel for a directory but I don't know how to do it for a single file, also I don't want to move the file in to a private directory because the file already been used in many places ?

any idea ?
 

4 comments

  1. Open a new text file called
    .htpasswd​
    Note the period at the beginning of the filename
  2. Use a password encryption program to create your passwords. Paste the lines into your .htpasswd file and save the file. You will have one line for every username that requires access
  3. Upload the .htpasswd file to a directory on your Web server that is not live on the Web. In other words, you should not be able to go to http://YOUR_URL/.htpasswd - it should be in a home directory or other location that is secure.
  4. Then you need to create your HTaccess file for the file you want to protect. Open a text file called
    .htaccess​
  5. Add the following to the file:
    AuthUserFile /path/to/htpasswd/file/.htpasswd
    AuthName "Name of Page"
    AuthType Basic
    <Files "mypage.html">
    require valid-user
    </Files>​
  6. Change
    /path/to/htpasswd/file/.htpasswd​
    to the full path to the .htpasswd file you uploaded in step 3.
  7. Change
    "Name of Page"​
    to the name of the page being protected.
  8. Change
    "mypage.html"​
    to the filename of the page you're protecting.
  9. Save the file and upload it to the directory of the file you want protected.
  10. Test that the password works by accessing the URL. If your password doesn't work, go back to the encryption programs and encrypt it again, remember that the username and password will be case-sensitive. If you are not prompted for a password, contact your system administrator to make sure that HTAccess is turned on for your site.

Source
http://webdesign.about.com/od/security/a/aa020801c.htm
 
Status
Not open for further replies.

About the author

T
Active Member · Joined
123
Messages
0
Reactions
16
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom