我在使HTTP授權正常工作時遇到一些困難。出於某種原因,我所得到的是彈出框,詢問用戶名和密碼。這是我正在使用的代碼。有人能告訴我我要去哪裏嗎?基本HTTP身份驗證
if ( !isset( $_SERVER['PHP_AUTH_USER'] ) || !isset( $_SERVER['PHP_AUTH_PW'] ))
{
authorizeUser();
//if no result, there is no user
}
else
{
$user = htmlentities(trim($_SERVER['PHP_AUTH_USER']));
$pass = htmlentities(trim($_SERVER['PHP_AUTH_PW']));
$pass = md5($_SERVER['PHP_AUTH_PW']);
//connect to MySQL data here//
$sql = "SELECT user_name,pwd FROM tableName WHERE user_name='$user' AND pwd='$pass'";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 0)
{
authorizeUser();
}
else
{
header("Location: somepage");
}
}
function authorizeUser()
{
header('WWW-Authenticate: Basic realm="Restricted Area"');
header('HTTP/1.0 401 Unauthorized');
echo "text if cancel button used";
}//end authorizedUser
查詢工作正常嗎? – janenz00
當我直接從phpmyadmin運行查詢時,它工作正常。儘管如此,我還是無法從腳本中看出來。 –
print $ sql輸出是什麼? – janenz00