【发布时间】:2013-02-10 17:08:33
【问题描述】:
试图实现一个非常简单的保护区。我有两个 php 文件:
第一个:secure.php
<?php
$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)) {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Secure Area"');
exit('You are not authorized');
}
?>
第二个:hello.php
<?php
require_once('secure.php');
?>
<doctype! html>
<head>
</head>
<body>
<p>hello</p>
</body>
</html>
访问 hello.php 时,系统会按预期提示我输入用户名/密码。但我没想到的是不断被拒绝访问。
You are not authorized
Authorization Required
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.
chrome 和 safari。我有什么明显的遗漏吗?
【问题讨论】:
标签: php authentication