MySQL php login
www login mysql phphej er der nogen her som kan hjælpe mig med dette, kan ikke komme til en side den spøger om kode hele tiden, men i mysql er user & pass ok
jeg ved ikke hvorfor den ikke kan komme ind?????
Mikica
<?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','root','pass') or die("Couldn't connect to the database.");
mysql_select_db('mydatabase') 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 {
// Escape both the password and username string to prevent users from inserting bogus data.
$PHP_AUTH_USER = addslashes($PHP_AUTH_USER);
$PHP_AUTH_PW = md5($PHP_AUTH_PW);
// Check username and password agains the database.
$result = mysql_query("SELECT count(id) FROM users 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) {
// If there were no matching users, show the login
displayLogin();
}
}
// All code/html below will only be displayed to authenticated users.
echo "Congratulations! You're now authenticated.";
?>