PHP Tutorials

Restrict a directory on the web server

.htaccess
AuthName "Realm name"
AuthType Basic
AuthUserFile /yourWebServerDirectory/yourRestrictedAreaDirectory/.htpasswd
require valid-user
.htpasswd
test:37aaS7/NBWyJA
Instructions
  • You have to put both files: .htaccess and .htpasswd in the root of the your directory
  • The password must be encrypted, see .htaccess Password Generator
  • The character encoding (or 'charset') of the files must be UTF-8

Find out the name of the diirectory on your provider's web server
test.php
<?
$show_me_the_directory_name = dirname(__file__);
echo $show_me_the_directory_name
?>
PHP Tutorials
Other Tutorials