【问题标题】:php can not authorizephp无法授权
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 2012-12-24
      • 2013-11-19
      • 2016-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      相关资源
      最近更新 更多