AUTH_USER vs LOGON_USER vs REMOTE_USER

狂风中的少年 提交于 2019-12-20 03:55:09

问题


I'm wanting to be able to get the information of the logged in user when they come on to our site so they don't need to log in. I've been told that it's only possible in I.E when your on windows IE. once they have signed in with their windows credentials.

I've searched the net and all three of these ($_SERVER['AUTH_USER'], $_SERVER['LOGON_USER'], $_SERVER['REMOTE_USER']) had been recommended so I'm not sure which one to check.

Second of all, I'm using windows server with IIS and no matter what I've tried and searched for on the net but nothing works. I can see the variables in the $_SERVER but all the above are empty strings.

How do I fix this problem?

For reference I'm using windows server 2012 with php v7.1

Also in my php.ini file I see that all of them have the following values.

$_SERVER['LOGON_USER']: no value (like so)

but I've also searched on how to set these in the .ini file without much luck.

header('WWW-Authenticate: NTLM', true);


// with this die there is a user and password prompt 
// if i click cancel then it sends the information through to the 
// server vars as expected.     
// when we cancel here it registers as two requests as my logs in the 
// log shows up two times.

// without it the login page loads with symfony but no values ever
// come through and i cant log in the user. 
die();

回答1:


In order to do so, the systems should be on a intranet network!

You can get system Username easily with the code below:

<?php echo getenv("username"); ?>

In order to obtain the logged in user firstly ensure you have windows authentication enabled and anonymous disabled. You have to send the NTLM-Authenticate headers first. After that, there should be the right user in the $_SERVER-Vars

header('WWW-Authenticate: NTLM');
$_SERVER['AUTH_USER'];

This only works on I.E and also you need to configure I.E for Automatic Logon

To configure Internet Explorer for automatic logon

  • Open the Internet Options dialog box by choosing Internet Options either from Control Panel or from the Tools menu in Internet Explorer.

  • In the Internet Options dialog box, on the Security tab, select Local intranet, and then click Custom Level.

  • In the Security Settings dialog box, under Logon, select Automatic logon only in Intranet zone, and then click OK.

  • In the Internet Options dialog box on the Security Settings tab with Local intranet still selected, click Sites.

  • In the Local intranet dialog box, click Advanced.

  • In the next dialog box (also titled Local intranet), type the URL of your Communicator Web Access site (for example, https://cwaserver.contoso.com) in the Add this Web site to the zone box, and then click Add.

  • In the Local intranet dialog, box click OK.

  • In the original Local intranet dialog box, click OK.

  • In the Internet Options dialog box, click OK.




回答2:


AUTH_USER

The name of the user as it is derived from the authorization header sent by the client, before the user name is mapped to a Windows account. This variable is no different from REMOTE_USER.

LOGON_USER

The only time LOGON_USER holds a different value than these other variables is if you have an authentication filter installed.

https://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx



来源:https://stackoverflow.com/questions/44697332/auth-user-vs-logon-user-vs-remote-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!