Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php无法授权_Php_Authentication - Fatal编程技术网

php无法授权

php无法授权,php,authentication,Php,Authentication,试图实现一个非常简单的保护区。我有两个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']

试图实现一个非常简单的保护区。我有两个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'); 
  }
?>
<?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都有。有什么明显的地方我遗漏了吗?

代码对我来说很好,所以可能是服务器配置问题,可能是这个-

代码对我来说很好,所以可能是服务器配置问题,可能是这个-