那就用php的header验证吧,
if(!(($PHP_AUTH_USER=="user")&&($PHP_AUTH_PW=="password"))||empty($PHP_AUTH_PW)||empty($PHP_AUTH_USER))
{
Header("WWW-Authenticate: Basic realm=\"新闻管理用户登录\"");
Header("HTTP/1.0 401 Unauthorized");
exit;
//Header("HTTP/1.0 403 Forbidden");
}
header("location:post.php");
if(!(($PHP_AUTH_USER=="user")&&($PHP_AUTH_PW=="password"))||empty($PHP_AUTH_PW)||empty($PHP_AUTH_USER))
{
Header("WWW-Authenticate: Basic realm=\"新闻管理用户登录\"");
Header("HTTP/1.0 401 Unauthorized");
exit;
//Header("HTTP/1.0 403 Forbidden");
}
header("location:post.php");
Session is the best choice.
对数据进行查询,看看数据库里有没有现在正要通过验证的这个人的名字!
当然密码也要正确!
如果查询的结果不等于0那么肯定有一条记录与现在正要通过验证的名字相同,
如果都相同的话,那么该用户正确进入,否则退出,输入的用户名不存在!
不知道可不可以 。
<?php
if (!isset($PHP_AUTH_USER)) {
header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
exit;
} else if (isset($PHP_AUTH_USER)) {
mysql_connect("hostname", "username", "password")
mysql_select_db("Authentication ")
$sql = "SELECT * FROM Accounts WHERE username='$PHP_AUTH_USER' and password='$PHP_AUTH_PW'"; //查询用户名密码是否存在
$result = mysql_query($sql);
$num = mysql_num_ows($result);
if ($num != "0") {
echo "<P>You're authorized!</p>";
exit;
} else {
header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
}
?>
改为:$num = mysql_num_rows($result);