Apache - 如何获取REMOTE_USER变量

4

之前我使用IIS服务器作为PHP服务器,现在改用了Apache。

在IIS上,我可以访问变量$_SERVER ['REMOTE_USER'],它返回用户名和域名(例如domain\user),但是在安装XAMPP后,这个变量不可用了。

我该怎么做才能再次获取这个变量呢?

我的应用程序在本地网络上,没有互联网连接。

4个回答

10
最终成功了! :D
  1. Download the module from here https://www.apachehaus.net/modules/mod_authnz_sspi/ (x86 for 32 bit and x64 for 64 bit apache)

  2. Copy the mod_authnz_sspi.so from Apache24\modules folder and place it in the modules folder of your Apache folder on your webserver

  3. Under the httpd.conf file (Config file for your apache) place this line of code. Try to load this as the last module:

    LoadModule authnz_sspi_module modules/mod_authnz_sspi.so

  4. Make sure that the following modules are uncommented

    LoadModule authn_core_module modules/mod_authn_core.so

    LoadModule authz_core_module modules/mod_authz_core.so

    PS: both the above modules are required for this to work.

  5. Place the following code in your httpd.conf file

    <Directory "path/to/your/htcdocs/folder"> 
    Options None 
    AllowOverride All 
    Order allow,deny 
    Allow from all 
    #AuthName "SSPI Protected Place" 
    AuthType SSPI 
    SSPIAuth On 
    SSPIAuthoritative On 
    SSPIOfferBasic On 
    SSPIOmitDomain On 
    Require valid-user 
    </Directory>
    
  6. Restart your apache servive and hopefully it should restart without any issues.

  7. Now in order to recognise the user , use the following code on a php page

    echo $_SERVER['PHP_AUTH_USER'];

这是全部内容。

我使用的是:

  • XAMPP控制面板3.2.1
  • APACHE 2.4

2
有人将其与新的mod_authn_ntlm模块进行比较吗?mod_authnz_sspi和mod_authn_ntlm似乎是同时发布的。有什么区别吗? - Mark Mikofski
自2023年起,apachehaus.net已关闭。我没有找到Apache 2.4版本的直接下载链接,但是我从“GLPI项目”中获取了我的版本。 - Neil

2
<Directory "path/to/your/htcdocs/folder"> 
Options None 
AllowOverride All 
Order allow,deny 
Allow from all 
#AuthName "SSPI Protected Place" 
AuthType SSPI 
SSPIAuth On 
SSPIAuthoritative On 
SSPIOfferBasic On 
SSPIOmitDomain On 
Require valid-user 
</Directory>

如果您使用ModRewrite或其他技术,请保留。
Options Indexes FollowSymLinks Includes ExecCGI

否则你会得到类似以下的错误:
[rewrite:error]: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions

1

只有当Apache实际认证了用户时,您才能访问远程用户,请查看apache auth howto


0

我为此苦战了很长时间,结果发现我必须安装VC可再发行程序才能使其正常工作。


运行XAMPP的机器需要注册到域名吗? - davejal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接