PHP_AUTH_USER 未设置?
由于某种原因,其中的代码都没有
if (isset($_SERVER['PHP_AUTH_USER']) &&
isset($_SERVER['PHP_AUTH_PW']))
{
// When the above is set, the code that is here will execute of course
}
为我执行。当我输入正确的用户名和密码时,再次弹出授权提示框。如果这两个字段都是正确的并且我按 Enter 键,那么它们不会被“设置”吗?但由于某种原因,情况并非如此。我可能做错了什么? 谢谢。
For some reason, none of the code within
if (isset($_SERVER['PHP_AUTH_USER']) &&
isset($_SERVER['PHP_AUTH_PW']))
{
// When the above is set, the code that is here will execute of course
}
is being executed for me. When I enter the correct username and password, the prompt box for the authorization again pops up. Wouldn't both fields be 'set' if they are correct and I press enter? But for some reason that is not the case. What can I be doing wrong?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
在 CGI 模式 PHP 中使用 HTTP 基本身份验证有一种“明智的方式”:在 .htaccess 中使用
和在 PHP 中使用
There is a 'sensible way' to use HTTP Basic Auth in CGI-mode PHP: in the .htaccess use
and in the PHP use
在您的 .htaccess 文件上尝试此操作
,您必须将其放入根目录
,然后
放入 php 脚本的开头
try this
on your .htaccess file which you will have to place into the root directory
and then
in the begining of your php scripts
我正在 Ubuntu 14.04 上使用在 PHP-PFM + Apache 2.4 上运行的 Symfony 2.5.7。
我有 BASIC_AUTH 工作,它需要通过添加以下内容来正确配置 Apache VirtualHost:
正如此处所述。
I am using Symfony 2.5.7 running on PHP-PFM + Apache 2.4 on Ubuntu 14.04.
I have BASIC_AUTH working, it needs to correctly configure the Apache VirtualHost by adding:
as also mentioned here.
从 Apache 2.4.13 开始,您只需使用 CGIPassAuth 指令:
Starting from Apache 2.4.13, you simply need to use CGIPassAuth directive in your .htaccess:
根据 phpinfo() ,我的服务器 API 是 CGI/Fast CGI,因此我通过将以下内容放入我的 .htaccess 文件中解决了该问题:
According to
phpinfo()
, my server API is CGI/Fast CGI, so I've solved the problem by putting the following in my.htaccess
file:尝试
$_SERVER['REMOTE_USER']
。这适用于 PHP 5.3 CGI + Apache 安装。Try
$_SERVER['REMOTE_USER']
. This works for me on a PHP 5.3 CGI + Apache installation.如果在 URL 中提供用户名/密码授予用户访问权限,请检查
您的 VHost/Directory/.htaccess 配置中是否有权限。
这针对我的用例修复了它。
If user access is granted giving username/password in URL please check if
is entitled in your VHost/Directory/.htaccess configuration.
This fixed it for my use case.
在我的主机的服务器上,使用
$_SERVER['REDIRECT_REMOTE_USER']
而不是$_SERVER['PHP_AUTH_USER']
On my host's servers, use
$_SERVER['REDIRECT_REMOTE_USER']
instead of$_SERVER['PHP_AUTH_USER']