Server-side redirects: .htaccess versus Meta Redirects - Password Protection / Authentication
(Page 3 of 6 )
Have you ever wanted a specific directory in your site to be available only to certain people? Have you ever found yourself frustrated with the holes in client-side options for this that allowed virtually anyone with enough skill to mess around in your source to get in? Then htaccess is the answer! There are numerous methods that let you password protect areas of your website, some server language bases (such as Java, PHP or ASP) and client-side-based, such as JavaScript. Htaccess is about as secure as you can or need to get in everyday life, though there are ways above and beyond even those of htaccess.
For example if you had uploaded some photos to your web site under the path - /album/ and want to share the photos ONLY with your girlfriend named Jessica, that name would need to be specified. The first thing you will need to do is create a file called .htpasswd or something else you like. You can use the httpd build-in program with the Apache Server called htpasswd.
>htpasswd –c /local/usr/.htpasswd Jessica
The program will prompt you to enter the password for the user Jessica, and then a file .htpasswd is created and stored in the path /local/usr/.htpasswd.
Secondly, you need to create the .htaccess file and place it under the /album/ directory with the following content:
AuthType Basic AuthName EnterPassword AuthUserFile /local/usr/.htpasswd Require user Jessica |
The above code fragment indicates that it will use Basic Authentication to authenticate the user, and only the user Jessica is allowed access to the /album/ directory.
Next: Enabling SSI (Server-Side Includes) >>
More JavaScript Articles
More By Stephen Davies