简体   繁体   English

如何使用带有Windows身份验证(NTLM)的PHP内置服务器来填充$ _SERVER [“ LOGON_USER”]?

[英]How to use the PHP built-in server with Windows Authentication (NTLM) to fill $_SERVER[“LOGON_USER”]?

I have scripts that use the $_SERVER["LOGON_USER"] which is obtained on my servers through IIS authentication settings. 我有使用$_SERVER["LOGON_USER"]脚本,该脚本是通过IIS身份验证设置在我的服务器上获得的。 I want this same variable to contain my domain\\username when running locally, or at least to have a way to set it when I fire up the PHP built-in server on localhost. 我希望该变量在本地运行时包含我的domain\\username ,或者至少在启动本地主机上的PHP内置服务器时具有一种设置它的方法。

How can I configure PHP on my machine to obtain and fill this variable the same way it does when running through IIS? 如何在我的计算机上配置PHP以获取并填充此变量,就像通过IIS运行时一样?

PS: I have seen this question , but the answer addresses $_ENV , not $_SERVER . PS:我看过这个问题 ,但是答案是$_ENV ,而不是$_SERVER

This is a workaround, if anyone has a better/proper solution (ie enabling NTLM), please post it as an answer and I'll accept it. 这是一种解决方法,如果有人有更好/合适的解决方案(即启用NTLM),请将其发布为答案,我会接受。

I was able to fill that variable using a router script. 我能够使用路由器脚本填充该变量。 According to the docs , this script is run at the start of each HTTP request, so I use it to set this variable when running locally. 根据docs ,此脚本在每个HTTP请求的开始处运行,因此在本地运行时,我使用它来设置此变量。

Also in my case, my environment had these two variables set, USERDOMAIN and USERNAME , so I used them to form the LOGON_USER server variable. 同样在我的情况下,我的环境设置了这两个变量USERDOMAINUSERNAME ,因此我使用它们来形成LOGON_USER服务器变量。

routerCredentials.php routerCredentials.php

<?php
$_SERVER["LOGON_USER"] = getenv("USERDOMAIN") . "\\" . getenv("USERNAME");
return false; // serve the requested resource as-is.

To use it, you just have to point to that file when you start the PHP built-in server: 要使用它,您仅需在启动PHP内置服务器时指向该文件:

php -S localhost:8000 "c:\somepath\routerCredentials.php"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM