Password Protection

The password protection and authentication is most important use of .htaccess files. The login procedure for these directories is automatically handled by the web browser using a pop-up login interface . you need two file for implementing password protection one is ".htaccess" file another is ".htpasswd" file.

.htaccess file

htaccess file should contain the following.

AuthType Basic AuthName "Password Protected Directory" AuthUserFile /path/to/.htpasswd Require valid-user

To find your ".htpasswd" file path create a php file and paste following code,and upload file in same directory where you uploaded your ".htpasswd" file.

<?php $dir=dirname(__FILE__); echo "Full path to a .htpasswd file in this dir: ".$dir."/.htpasswd".; ?>

.htpasswd file

.htpasswd file should contain:


Above code will allow the user "admin" to access the password proteced directory with the password "test".