RSS

Tag Archives: php full path

Protect website with htpasswd and htaccess

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 .htaccess. A .htpasswd file will be used to store login details.

Add following code into your .htaccess file

AuthType Basic
AuthName “My Protected Area”
AuthUserFile /path/to/.htpasswd
Require valid-user

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>";
?>
 
Leave a comment

Posted by on May 28, 2012 in Uncategorized

 

Tags: , , ,