Kinetic Pulse
  • Home
  • Services
  • Portfolio
  • Blog
  • Terms
  • Contact

Password protect a folder on your PHP site

May 17, 2012

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:

  • Private Area will be the title of your box – depending on your browser, so this can be changed to something more meaningful.
  • You will get a 500 server misconfiguration message if the system can”t find you passwords file
  • The “require valid-user” line will let in any user who is listed in the passwords file (you can have multiple users)
  • Some hosts will lock your IP address out if you have too many incorrect login attempts (I found this out to my cost today. Cue lots of time spent re-booting my router to get different IP addresses!)

I hope this is helpful to some of you.

Share

Facebook Google+ Twitter Pinterest Email
  1. Laura says

    June 24, 2012 at 1:00 pm

    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!

Back to Blog

Testimonials

I like it.  I like it a lot !!!

 You have interpreted what I wanted to achieve perfectly considering what you have to play with i.e not redoing the whole thing in the process.

Fiona Simmons-MooreSouth Gloucestershire Parents & Carers
Thank you for all of your hard work its looks fab and I am over the moon with it!
Amanda MercerAmanda Mercer Ceramics
Absolutely fantastically professional web developer – I would highly recommend!!! Thank you so much Kinetic Pulse!
Tania MarstonDoris Designs
Thanks so much for all your work on this, really appreciated. It’s come on in leaps and bounds since you took over.
Pete KewRedwood Strip Curtains
It’s been fab working with you – we love the site and certainly going to recommend you!
James DaviesThirty Eight Degrees North
Thank you guys so much for all that you’ve done helping us to create a really awesome website!! We get such great feedback – everyone loves it & we couldn’t be prouder! Look forward to working with you again soon!
Wild Thyme PlantsWild Thyme Plants
Amazing and brilliant, Kinetic Pulse have lifted a dream to reality, Highly recommended and great if you are total novice, they know their stuff…Thanks again
Annie LindridgeSalt Yourself Out

Copyright 2025 Kinetic Pulse