PDA

Click to See Complete Forum and Search --> : Why doesn't this auth stuff work...


filburt1
Jun 20th, 2002, 10:03 AM
$auth = false;
$authuser = $_SERVER['php_auth_user'];
$authpass = $_SERVER['php_auth_pw'];
if (isset($authuser) && isset($authpass))
{
$result = mysql_query('SELECT name,passhash FROM users WHERE id=1');
if (!$result)
{
echo 'Failed to determine root user\\'s name.';
exit;
}
else
{
$s = mysql_fetch_row($result);
$name = $s[0];
$passhash = $s[1];
if ($authuser == $name && md5($authpass) == $passhash)
{
$auth = true;
}
}
}
if (!$auth)
{
header("WWW-Authenticate: Basic realm=\"Garnet Server Login\"");
header('HTTP/1.0 401 Unauthorized');
echo 'Login failed.';
exit;
}

I tested the query and it works fine (i.e., returns the name and password hash). But the authentication dialog that pops up never accepts the username and password.

filburt1
Jun 20th, 2002, 10:27 AM
Fixed it...changed the case of the array keys for the $_SERVER stuff.