如何在PHP中进行身份认证

〈?

if(!isset( $PHP_AUTH_USER))
{
Header("WWW-Authenticate: Basic realm=请输入你的用户名和密码:");
Header("HTTP/1.0 401 Unauthorized");
echo "验证失败,你不能网络资源!";
exit;
}
else
{
if ( $PHP_AUTH_USER!="username" or $PHP_AUTH_PW!="password")
{
Header("HTTP/1.0 401 Unauthorized");
echo "验证失败,你不能网络资源!";
exit;
}
}

?〉

--------------------------------------------------------------------
注意:此代码必须放到网页页首(即在执行此代码时,网页无任何输出),否则将会出错。

Published At
Categories with Web编程
Tagged with
comments powered by Disqus