<?php
// User name and password for authentication
$username = 'USER';
$password = 'PASSWORD';
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
($_SERVER['PHP_AUTH_USER'] != $username) || ($_SERVER['PHP_AUTH_PW'] != $password)) {
// The user name/password are incorrect so send the authentication headers
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="The Manor Cheadle"');
exit('<h2>The Manor Cheadle</h2>Sorry, you must enter a valid user name and
password to access this page.');
}
?>
and is referenced at the top of every page:
<?php
require_once('authorize.php');
?>
任何想法如何绕过这个并让它发挥作用?
提前致谢
答案 0 :(得分:0)
我总是将它用于简单的身份验证,从来没有遇到过问题。但它看起来与你的非常相似。
<?
$auth = 0;
if (!isset($_SERVER['PHP_AUTH_USER']))
{
header('WWW-Authenticate: Basic realm="Login"');
header('HTTP/1.0 401 Unauthorized');
print "you need to login";
exit;
}
else
{
if ($_SERVER['PHP_AUTH_USER'] == "UserName" and $_SERVER['PHP_AUTH_PW'] == "Password")
{
$auth=1;
}
else
{
header('WWW-Authenticate: Basic realm="Login"');
header('HTTP/1.0 401 Unauthorized');
print "you need to login";
exit;
}
}
if ($auth==0) {
print "you need to login";
exit;
}
?>