WhatsApp Chat
Send us a message today and we will contact you as soon as possible.

Here are the final steps for how to get a password protected folder on your PHP site.
As it took me ages to get it working, I thought I”d document it here so you dont have to spend ages too!

1) Create a folder outside of the main public html visible web folder – this hosting had a folder called .htpasswrds, but you can easily create your own. It needs to be outside the main web site folder to prevent it being read. (Even though the passwords are encrypted, the accounts could potentially be hacked witha brute force attack)
2) Create a .htpasswrd file. Just a plain text file, like the .htaccess file
3) Create a name & password for your protected folder using the facility here
http://www.clockwatchers.com/htaccess_tool.html

4) Copy the line it creates for you and paste it in the .htpasswd file and save it
5) In the folder you want to password protect, create online pokies (or add) the folowing to your .htaccess file


AuthUserFile /home/pathtoyoursite/.htpasswds/.htpasswd
AuthGroupFile /dev/null
AuthName "Private Area"
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>

This should be enough for you to get prompted for a password each time you access that folder.
Note:

I hope this is helpful to some of you.

One Response

  1. Just to add – make sure that your .htpasswds file is the one in your hosting root! I had copied a site which had another .htpasswds file within the main web site folder so I was updating *that* and wondering why I couldn’t log in. Doh! I guess thats another reason to maintain a tidy code structure!