Sometimes we need to protect our website or website directories with username and password while we are working on development server. Password protect one or more directories with Basic HTTP Authentication using
.htpasswd file will be used to store login details.
Add following code into your .htaccess file
AuthName “My Protected Area”
Auth name: This name will be displayed in the login box when a user access your protected area for the first time.
AuthUserFile: you need to enter the full path of your .htpasswd file here. Use the following PHP script to find the full path of you .htpasswd file
<?php $dir = dirname(__FILE__); echo "<p>Full path to this dir: " . $dir . "</p>"; echo "<p>Full path to a .htpasswd file in this dir: " . $dir . "/.htpasswd" . "</p>"; ?>