How to add password protection to a website

Posted on February 27th, 2009 in Tutorials | Tags: , , , ,

Question: I have a website that I don’t want accessible to the general public. What is the best, most reliable and secure way to add password protection to my website (or section of my website) to make it secure?

Answer: there are a few different ways to add password protection to sites and pages: PHP, JavaScript, and htaccess. Depending on what you are trying to do with determine which method will be best for your application.

If I had a section of my website that was for members only (who I would like to sign up on my site), I would use PHP to manage the accounts created by the users, and logging users into the “members only” section of my website.

However, let’s look at a different case. Let’s say I’ve been developing a website for a client, locally, on my machine. Now I’m ready to show the client, but I don’t want the rest of the world to be able to see my “work in progress.” This is an example where htaccess would be best.

With htaccess, you will create a file on your server, telling your server to restrict access to only those people who provide the correct login credentials. Htaccess is EASY to set up and is among the most secure options available.

For a tutorial on how to set up htaccess, I found this tutorial to be quite helpful: Comprehensive Guide to .htaccess

Leave a Comment

Contact Form