Forum Moderators: coopster
mysql_connect($host ,$user,$pass) or die("Unable to connect to database");
mysql_select_db("$db") or die("Unable to select database $db");
if (!isset($PHP_AUTH_USER)) {
// If empty, send header causing dialog box to appear
header('WWW-Authenticate: Basic realm="Please Log In"');
header('HTTP/1.0 401 Unauthorized');
exit;
} else if (isset($PHP_AUTH_USER)) {
// Formulate the query
$sql = "SELECT * FROM $utable WHERE username='$PHP_AUTH_USER' and user_password='$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql);
// Get number of rows in $result. 0 if invalid, 1 if valid.
$num = mysql_num_rows($result);
if ($num!= "0") {
header("Location: test2.php");
exit;
} else {
header('WWW-Authenticate: Basic realm="Perhaps you mistyped something, please try again."');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
}
?>
$sql = "SELECT * FROM $utable WHERE username='$PHP_AUTH_USER' and user_password='" . md5 [php.net]($PHP_AUTH_PW) . "'";