PHP_AUTH_USER 未设置?

发布于 2024-09-18 11:40:34 字数 312 浏览 8 评论 0原文

由于某种原因,其中的代码都没有

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

浅浅淡淡 2024-09-25 11:40:34

在 CGI 模式 PHP 中使用 HTTP 基本身份验证有一种“明智的方式”:在 .htaccess 中使用

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

和在 PHP 中使用

list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = 
  explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));

There is a 'sensible way' to use HTTP Basic Auth in CGI-mode PHP: in the .htaccess use

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

and in the PHP use

list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = 
  explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
娇俏 2024-09-25 11:40:34

在您的 .htaccess 文件上尝试此操作

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

,您必须将其放入根目录

,然后

list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':' , base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));

放入 php 脚本的开头

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

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

浅唱々樱花落 2024-09-25 11:40:34

我正在 Ubuntu 14.04 上使用在 PHP-PFM + Apache 2.4 上运行的 Symfony 2.5.7。
我有 BASIC_AUTH 工作,它需要通过添加以下内容来正确配置 Apache VirtualHost:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

正如此处所述。

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:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

as also mentioned here.

撩动你心 2024-09-25 11:40:34

从 Apache 2.4.13 开始,您只需使用 CGIPassAuth 指令:

CGIPassAuth On

Starting from Apache 2.4.13, you simply need to use CGIPassAuth directive in your .htaccess:

CGIPassAuth On
暮年慕年 2024-09-25 11:40:34

根据 phpinfo() ,我的服务器 API 是 CGI/Fast CGI,因此我通过将以下内容放入我的 .htaccess 文件中解决了该问题:

RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]

According to phpinfo(), my server API is CGI/Fast CGI, so I've solved the problem by putting the following in my .htaccess file:

RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
咆哮 2024-09-25 11:40:34

尝试$_SERVER['REMOTE_USER']。这适用于 PHP 5.3 CGI + Apache 安装。

Try $_SERVER['REMOTE_USER']. This works for me on a PHP 5.3 CGI + Apache installation.

虫児飞 2024-09-25 11:40:34

如果在 URL 中提供用户名/密码授予用户访问权限,请检查

AuthType Digest

您的 VHost/Directory/.htaccess 配置中是否有权限。

这针对我的用例修复了它。

If user access is granted giving username/password in URL please check if

AuthType Digest

is entitled in your VHost/Directory/.htaccess configuration.

This fixed it for my use case.

素罗衫 2024-09-25 11:40:34

在我的主机的服务器上,使用 $_SERVER['REDIRECT_REMOTE_USER'] 而不是 $_SERVER['PHP_AUTH_USER']

On my host's servers, use $_SERVER['REDIRECT_REMOTE_USER'] instead of $_SERVER['PHP_AUTH_USER']

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文