php 如何设置 PHP_AUTH_USER

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3565912/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:15:05  来源:igfitidea点击:

How to set PHP_AUTH_USER

phpauthenticationcredentials

提问by zod

PHP_AUTH_USER is empty. And system using the Windows login credentials.

PHP_AUTH_USER 为空。和系统使用 Windows 登录凭据。

How can I change it.

我怎样才能改变它。

I wanna use the username and password entered by the user

我想使用用户输入的用户名和密码

回答by Gordon

See HTTP Authentication with PHP

请参阅使用 PHP 进行 HTTP 身份验证

<?php
  if (!isset($_SERVER['PHP_AUTH_USER'])) {
       Header("WWW-Authenticate: Basic realm=\"My Realm\"");
       Header("HTTP/1.0 401 Unauthorized");
       echo "Text to send if user hits Cancel button\n";
       exit;
       } else {
   echo "Hello {$_SERVER['PHP_AUTH_USER']}";
   echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
  }
?> 

And the description of inidices in $_SERVER:

以及inidices描述$_SERVER

  • 'PHP_AUTH_USER': When running under Apache or IIS (ISAPI on PHP 5) as module doing HTTP authentication this variable is set to the username provided by the user.

  • 'PHP_AUTH_PW': When running under Apache or IIS (ISAPI on PHP 5) as module doing HTTP authentication this variable is set to the password provided by the user.

  • 'PHP_AUTH_USER':当在 Apache 或 IIS(PHP 5 上的 ISAPI)下作为模块执行 HTTP 身份验证时,此变量设置为用户提供的用户名。

  • 'PHP_AUTH_PW':在 Apache 或 IIS(PHP 5 上的 ISAPI)下作为模块执行 HTTP 身份验证时,此变量设置为用户提供的密码。

回答by djn

If you're running PHP under IIS and using Windows Authentication you shoud find the username under one (or more) of these:

如果您在 IIS 下运行 PHP 并使用 Windows 身份验证,您应该在其中一个(或多个)下找到用户名:

  • $_SERVER['LOGON_USER']
  • $_SERVER['AUTH_USER']
  • $_SERVER['REDIRECT_LOGON_USER']
  • $_ENV['REDIRECT_LOGON_USER']
  • $_SERVER['LOGON_USER']
  • $_SERVER['AUTH_USER']
  • $_SERVER['REDIRECT_LOGON_USER']
  • $_ENV['REDIRECT_LOGON_USER']

Forget about the password - when PHP starts the user has already been authorized and the script is not supposed to need it.

忘记密码 - 当 PHP 启动时,用户已经被授权,脚本不需要它。

You can use Windows Authentication to log into SQL server as the user: look at the documentaion for fastcgi.impersonate. This works as long as IIS and SQL Server are on the same system. If you keep your database elsewhere... well, you may google for Double Hop issueif you want the gory details, but the short story is that it doesn't work. I've lost a month waiting for a customer to give up and allow a plain user/pass login into his database.

您可以使用 Windows 身份验证以用户身份登录 SQL 服务器:查看fastcgi.impersonate的文档。只要 IIS 和 SQL Server 在同一个系统上,这就会起作用。如果你把你的数据库放在别处……好吧,如果你想要血腥的细节,你可以用谷歌搜索双跳问题,但简短的故事是它不起作用。我花了一个月的时间等待客户放弃并允许普通用户/密码登录他的数据库。

回答by nxd4n

As this came up when searching for IIS and auth_user missing, I probably found an explanation why : if you set the folder permissions to everyone : read and execute, the $_SERVER['_USER'] get no value.

由于这是在搜索 IIS 和 auth_user 丢失时出现的,我可能找到了一个解释:如果您将文件夹权限设置为每个人:读取和执行,则 $_SERVER['_USER'] 没有任何价值。

回答by Zardiw

On JodoHost use $_SERVER['REDIRECT_REMOTE_USER']instead of $_SERVER['PHP_AUTH_USER'].

在 JodoHost 上使用$_SERVER['REDIRECT_REMOTE_USER']而不是$_SERVER['PHP_AUTH_USER'].

Also, if you want to see all the Server Variables, make a small PHP Test page and put the PHP Code below in it.

此外,如果您想查看所有服务器变量,请制作一个小的 PHP 测试页面并将 PHP 代码放入其中。

If you've logged in as a user, you'll see which field has your user name.

如果您以用户身份登录,您将看到哪个字段包含您的用户名。

Also, put this test file into the directory that is protected by .htaccess:

另外,将此测试文件放入受 .htaccess 保护的目录中:

PHP CODE:

代码:

foreach($_SERVER as $key_name => $key_value) 
{
    print $key_name . " = " . $key_value . "<br>";
}