I'm having some trouble using the unset() with php4. I am working with login's and would like to have the PHP_AUTH box pop up again and again if necessary, if the user enters faulty information. Currently if the data entered is valid, every thing works fine. And if the user clicks the cancel button, then again, the pop up box returns as desired and everything is ok.
However if they enter the wrong username or password, then I cannot get the AUTH box to pop up again. I am using the unset($PHP_AUTH_USER) so that my test...if (!isset($PHP_AUTH_USER)...will bring back the user and password box if they click on the login link again.
Thanks
John
Code below...
if (!isset($PHP_AUTH_USER))
{
header("WWW-Authenticate: Basic realm=\"Knowledge Base\"");
header("HTTP/1.0 401 Unauthorized");
echo "You must authenticate to log in.<br>";
unset($PHP_AUTH_USER);
exit;
}
else
{
$query = "SELECT * FROM users WHERE ";
$query .= "UserName='$PHP_AUTH_USER' AND Password='$PHP_AUTH_PW'";
$result = mysql_query($query,$link);
$num_rows = mysql_num_rows($result);
if ($num_rows <= 0)
{
unset($PHP_AUTH_USER);
print "Authentication Failed.<br>";
exit;
}
else
{
header("Location: menu.php");
}
}