Can someone show me what exactly needs to reside in this .htaccess file in order to password protect it?
Hopefully it some simple XML or something???
Cheers
Moderator: General Moderators
Yea I know how to google tootrukfixer wrote:http://httpd.apache.org/docs/1.3/howto/auth.html
Code: Select all
<?
if($_SERVER['PHP_AUTH_USER'] == "William" && $_SERVER['PHP_AUTH_PW'] == "mypass") {
echo "You are now loggedin!";
} else {
header("WWW-Authenticate: Basic realm=\"".$login_text."\"");
header("HTTP/1.0 401 Unauthorized");
echo "Authorization Required.";
exit;
}
?>Now you put that in your .htaccess file and you can change Simple Login Script to whatever you want in the popup box. Now you set the AuthUserFile to the path of a .htpasswd file... for instance... /home/hockey/public_html/.htpasswd now inside that file you put a list of usernames and passwords in the following format:AuthName "Simple Login Script"
AuthType Basic
AuthUserFile /full/path/to/.htpasswd
Require valid-user
you can keep adding to the list for more accounts. Also one thing you need to know is that the password must be encrypted! For a easy way to get the encryption you can go to: http://www.kxs.net/support/htaccess_pw.html Just type your username & password and it will give you the user:pass line for you! Well I hope that helps you out the .htaccess thing I never use so I hope it works correctly. Good luck!username:password
Oh nice...didn't even think of tackling it that way...William wrote:Well there are different ways of doing this. You can either do it in .htaccess or in PHP. I like doing it in PHP because then it is easier to use with MySQL databases. Below is a PHP script:
To put it simple $_SERVER['PHP_AUTH_USER'] is the variable of the username field and $_SERVER['PHP_AUTH_PW'] is the variable for the password field of the login popup. Now we need to make it popup the login! So we added the header("WWW-Authenticate: Basic realm="Simple Login Script""); function which sends a header telling it to basically make that popup. Now where it says Simple Login Script you put what you want the popup box to say. Now the header("HTTP/1.0 401 Unauthorized"); says that if it was unauthorized to display a 404 error. and whatever is under that is what will show when the user clicks cancel. I have it set to check to see if the user is William and the pass is MyPass and if not then obviously they either typed the wrong information or its not set... Then it makes the popup. If you have anymore questions please let me know!Code: Select all
<? if($_SERVER['PHP_AUTH_USER'] == "William" && $_SERVER['PHP_AUTH_PW'] == "mypass") { echo "You are now loggedin!"; } else { header("WWW-Authenticate: Basic realm="".$login_text."""); header("HTTP/1.0 401 Unauthorized"); echo "Authorization Required."; exit; } ?>
Now for the .htaccess way you can do this:
Now you put that in your .htaccess file and you can change Simple Login Script to whatever you want in the popup box. Now you set the AuthUserFile to the path of a .htpasswd file... for instance... /home/hockey/public_html/.htpasswd now inside that file you put a list of usernames and passwords in the following format:AuthName "Simple Login Script"
AuthType Basic
AuthUserFile /full/path/to/.htpasswd
Require valid-user
you can keep adding to the list for more accounts. Also one thing you need to know is that the password must be encrypted! For a easy way to get the encryption you can go to: http://www.kxs.net/support/htaccess_pw.html Just type your username & password and it will give you the user:pass line for you! Well I hope that helps you out the .htaccess thing I never use so I hope it works correctly. Good luck!username:password