WWW -Authenticate
Hvad er der galt med script det virker bare ikke :(bruger php 5.2 med register_globals = off
<?PHP
function displayLogin() {
header("WWW-Authenticate: Basic realm=\"My Website\"");
header("HTTP/1.0 401 Unauthorized");
echo "<h2>Authentication Failure</h2>";
echo "The username and password provided did not work. Please reload this page and try again.";
exit;
}
$db = mysql_connect('localhost','****','******') or die("Couldn't connect to the database.");
mysql_select_db('brugerdb') or die("Couldn't select the database");
if (!isset($PHP_AUTH_USER) || !isset($PHP_AUTH_PW)) {
// If username or password hasn't been set, display the login request.
displayLogin();
} else {
$PHP_AUTH_USER = addslashes($PHP_AUTH_USER);
$PHP_AUTH_PW = md5($PHP_AUTH_PW);
$result = mysql_query("SELECT count(id) FROM brugere WHERE password='$PHP_AUTH_PW' AND username='$PHP_AUTH_USER'") or die("Couldn't query the user-database.");
$num = mysql_result($result, 0);
if (!$num) {
displayLogin();
}
}
echo "Congratulations! You're now authenticated.";
?>
