Not a Member Yet,
Click here to Register

ID: 87
Viewed: 6181
Added: Jun 27, 2019
Version: php4.1+
Snippet uploaded by: snippet
Written By: snippet
Demo: Sorry, no demo



User Rated at: 5 Stars5 Stars5 Stars5 Stars5 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

This brings up a password window where the user has to enter a username and password. it then checks with Mysql to see if the username and password are real (compares it to the original). it then will load a page for the user to see or it will bring it up the password box again.<br /><br />Put the following in a separate PHP file and include it on all your protected files: <br /><br />Note: This will not work work if your server is setup in CGI mode.

<!---Head--->
none

<!---Body--->


 <?php

if (!empty($_SERVER['PHP_AUTH_USER'])) {

header('WWW-Authenticate: Basic realm="Login"');
header('HTTP/1.0 401 Unauthorized');
exit;

} else if (isset($_SERVER['PHP_AUTH_USER'])) {

$sql = "SELECT * FROM users WHERE use\r\name='".htmlentities($_SERVER['PHP_AUTH_USER'])."' and password='".htmlentities($_SERVER['PHP_AUTH_PW'])."'";
$result = mysql_query($sql);
$num = mysql_num_rows($result);

if ($num != 1) {
header('WWW-Authenticate: Basic realm="Login"');
header('HTTP/1.0 401 Unauthorized');
exit;
} else{
// show page you want them to see here
}

?>


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 snippetlibrary.com All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!