How to protect your admin directory. 


Most of the scripts that i create now have an admin directory for inserting updating creating and generally monitoring the script on your site.  You will probably not want everyone to have access to this directory.  The best way to protect it is by using Apache .htaccess



you need to know the full path to the directory you want to protect.
example:
/home/WEBHOTEL1/yoursite_name/WWW/directory_to_protect

The first thing you need to do is create password file. ssh or telnet to the server that your web site is on.  create a file called .htaccess  put the following in it.



// file start here
AuthName "your site name "
AuthType Basic
AuthUserFile path_to_dir_to_protect/passwords
require valid-user
// file end here

if we use the example above the AuthUserFile would look like this
AuthUserFile /home/WEBHOTEL1/yoursite_name/WWW/directory_to_protect/passwords


No once you have created that file we will need to make a passwords file. the command is


htpasswd -c passwords <user_name>


You will be prompted for a password and prompted again to retype it.



htpasswd -c passwords kill-9



Now try and access the directory. you will see a nice little login screen where it will prompt you for a username and password.


Note: you may create more then one login if you like by just calling htpasswd again with out the -c
example:
htpasswd  passwords kill-9

The reason you don't use the -c again is that -c creates the file passwords.


Hope this was of some help and you now have complete protection of your admin directory.
