Thursday , 23 March 2017
Home » .htaccess » Password Protection Pages with .htaccess & .htpasswd
Password Protection Pages with .htaccess & .htpasswd

Password Protection Pages with .htaccess & .htpasswd

Hello Friends,

I was working with .htaccess since a long time but I used .htaccess with .htpasswd for the first time in my 5 years of development. I did not came across any requirement like this before so never used before. Recently I need to implement password protected pages for one of my client. So I searched for it and came to know that we can do it using .htaccess and .htpasswd.

In .htpasswd, all username and password will be saved. Passwords are in encrypted forms. In .htaccess file, we are giving .htpasswd path to search for username and password. and than validate using it. Here we go with the code of .htaccess and .htpasswd.

1. .htpasswd

rakshit:pZV.Ta3.KLa2o

Password is rakshit but it is in encrypted form.

2. .htaccess

AuthName "Restricted Area" 
AuthType Basic 
AuthUserFile /home/.htpasswd 
<Files test.php>
require valid-user
</Files>

SO now when you try to open test.php file, it will ask for authorization. When you enter rakshit/rakshit, than only it permits you to view the page. Isn’t it easy ?

Note: Remember, try to keep your .htpasswd file outside public_html folder. It is not required but keeping the file outside of public_html folder is safe. Just a security reason.

Password Protection using .htaccess and .htpasswd, How to Protect pages using .htaccess, Password Protection using .htpasswd, Password Protection using .htaccess, How to protect pages using .htpasswd, Generate Password of .htpasswd, for all of above, you will find the answer here.

      
Plugin by: PHP Freelancer

About Rakshit Patel

I am PHP Freelancer, Rakshit Patel working as PHP Programmer India. I have developed this site to share my knowledge, thoughts and experience during the development of projects. We are group of developers working together. If you want to hire us for any PHP related work, you can reach me via Email, Phone or Chat.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.