Password Protect a Directory Using .htaccess

RussianRoot 01/07/2013 0
Password Protect a Directory Using .htaccess

Protecting files on your website from unauthorized users can be very important. Even more important is the method by which you accomplish this task. You could use PHP to listen for login authorization information on each page, but that doesn’t protect your images, documents, and other media, does it?

The system requires two files — the .htaccess file and .htpasswd file.

The .htaccess Code

The above code protects a directory called “secret_dir” at root level.  The “AuthUserFile” value is always specific to your hosting configuration. If you don’t know what the value should be, do aphpinfo() and find the DOCUMENT_ROOT value.

The .htpasswd Code

The .htpasswd file contains the usernames and passwords of allowed users. One per line. The passwords are crypted for security purposes.

Leave A Response »

6 × = 36

Warning: require_once(/www/htdocs/w00e1ca9/domainpool/ failed to open stream: No such file or directory in /www/htdocs/w00e1ca9/domainpool/ on line 48

Fatal error: require_once(): Failed opening required '' (include_path='.:/usr/share/php:..') in /www/htdocs/w00e1ca9/domainpool/ on line 48