I am having a problem with authentication. First, here is the code I use on the relevant pages:
if(!isset($PHP_AUTH_USER)) {
Header('WWW-Authenticate: Basic realm="Realm Name"');
Header("HTTP/1.0 401 Unauthorized");
echo "Authorization failed.";
exit;
} else {
$result = mysql_query('SELECT password FROM users WHERE username="'.$PHP_AUTH_USER.'";');
$row = mysql_fetch_row($result);
if(($PHP_AUTH_PW != $row[0]) or (mysql_num_rows($result) == 0)) {
Header('WWW-Authenticate: Basic realm="Realm Name"');
header("HTTP/1.0 401 Unauthorized");
echo "Authorization failed.";
exit;
}
}
My problem is that once in a while, it asks for authentication again and won't accept any password at all. The only solution at that point is to restart the browser, and sometimes I've had to do that twice. Is there a better way to do this?