Apache - how to get REMOTE_USER variable

后端 未结 4 1946
别那么骄傲
别那么骄傲 2020-12-01 11:29

Previously I used the IIS server as PHP server. Currently, it is the apache.

On IIS I could access to the variable $_SERVER [\'REMOTE_USER\'] which retu

相关标签:
4条回答
  • 2020-12-01 12:09

    You can only access the remote user if Apache has actually authenticated the user, check the apache auth howto.

    0 讨论(0)
  • 2020-12-01 12:16

    I battled with this for a long time, it turned out that I had to install VC redistributable to make it work.

    0 讨论(0)
  • 2020-12-01 12:23
    <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>
    

    If you use ModRewrite or other I suggest you to keep

    Options Indexes FollowSymLinks Includes ExecCGI
    

    otherwise you'll get an error like

    [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
    
    0 讨论(0)
  • 2020-12-01 12:33

    Finally got it to works! :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'];

    That's all.

    I'm using:

    • XAMPP Control Panel 3.2.1
    • APACHE 2.4
    0 讨论(0)
提交回复
热议问题