php PHP_AUTH_USER 未设置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3663520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP_AUTH_USER not set?
提问by Newbie_25
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.
正在为我处决。当我输入正确的用户名和密码时,再次弹出授权提示框。如果两个字段都正确并且我按回车键,它们不会都被“设置”吗?但由于某种原因,情况并非如此。我会做错什么?谢谢你。
回答by ChrisV
There is a 'sensible way' to use HTTP Basic Auth in CGI-mode PHP: in the .htaccess use
在 CGI 模式的 PHP 中,有一种“明智的方式”可以使用 HTTP 基本身份验证:在 .htaccess 中使用
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
and in the PHP use
并在 PHP 中使用
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) =
explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
回答by a.boussema
try this
尝试这个
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>
on your .htaccess file which you will have to place into the root directory
在您必须将其放入根目录的 .htaccess 文件中
and then
进而
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
in the begining of your php scripts
在你的 php 脚本的开头
回答by thePanz
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:
我在 Ubuntu 14.04 上使用在 PHP-PFM + Apache 2.4 上运行的 Symfony 2.5.7。我有 BASIC_AUTH 工作,它需要通过添加正确配置 Apache VirtualHost:
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
SetEnvIf 授权 "(.*)" HTTP_AUTHORIZATION=$1
as also mentioned here https://stackoverflow.com/a/17490827/435956
回答by Yerkezhan
In my phpinfo() Sever API is CGI/Fast CGI. So I've solved my problem with writing following in my .htaccess file
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
在我的 phpinfo() 服务器 API 中是 CGI/Fast CGI。所以我已经解决了在我的 .htaccess 文件中写入以下内容的问题
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
回答by MrAnonymous
Try $_SERVER['REMOTE_USER']
. This works for me on a PHP 5.3 CGI + Apache installation.
试试$_SERVER['REMOTE_USER']
。这适用于 PHP 5.3 CGI + Apache 安装。
回答by childno?.de
If user access is granted giving username/password in URL please check if
如果用户访问被授予在 URL 中提供用户名/密码,请检查是否
AuthType Digest
is entitled in your VHost/Directory/.htaccess configuration.
在你的 VHost/Directory/.htaccess 配置中被授权。
This fixed it for my use case.
这为我的用例修复了它。
回答by Zardiw
On my host's servers, use $_SERVER['REDIRECT_REMOTE_USER']
instead of $_SERVER['PHP_AUTH_USER']
在我主机的服务器上,使用$_SERVER['REDIRECT_REMOTE_USER']
而不是$_SERVER['PHP_AUTH_USER']