PHP equivalent of request.getRemoteUser()
Moderator: General Moderators
PHP equivalent of request.getRemoteUser()
Hello, what is the PHP equivalent of JSP's request.getRemoteUser()? Thank you in advance.
Re: PHP equivalent of request.getRemoteUser()
My JSP is very rusty, but I think that method returns the same as PHP's $_SERVER['REMOTE_USER'].
Re: PHP equivalent of request.getRemoteUser()
Thank you for the reply. I've tried the:
$_SERVER['PHP_AUTH_USER']
$_SERVER['REMOTE_USER']
But it returns null. Unlike in JSP's request.getRemoteUser() using Internet Explorer browser it will return the Windows' username of the local PC. It gets its value from Windows' username environment variable. Can PHP access this?
$_SERVER['PHP_AUTH_USER']
$_SERVER['REMOTE_USER']
But it returns null. Unlike in JSP's request.getRemoteUser() using Internet Explorer browser it will return the Windows' username of the local PC. It gets its value from Windows' username environment variable. Can PHP access this?
Re: PHP equivalent of request.getRemoteUser()
try running this
[codete=php]<pre>
<? var_dump($_SERVER); ?>
</pre>[/quote]
for some clues.
[codete=php]<pre>
<? var_dump($_SERVER); ?>
</pre>[/quote]
for some clues.
Re: PHP equivalent of request.getRemoteUser()
Thank you for the reply. I tried the:
var_dump($_SERVER);
It didn't show any username = administrator
Maybe I'm missing something during the PHP setup with IIS. Like in JSP you need to append this string “request.tomcatAuthentication=false” in jk2.properties file in able not to receive null
in executing request.getRemoteUser() function. Is there same thing in PHP?
The output of var_dump($_SERVER);:
array(40) { ["ALL_HTTP"]=> string(322) "HTTP_ACCEPT:*/* HTTP_ACCEPT_LANGUAGE:en-us HTTP_CONNECTION:Keep-Alive HTTP_HOST:localhost HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Alexa Toolbar; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; MEGAUPLOAD 2.0) HTTP_UA_CPU:x86 HTTP_ACCEPT_ENCODING:gzip, deflate " ["HTTPS"]=> string(3) "off" ["SCRIPT_NAME"]=> string(9) "/ldap.php" ["HTTP_COOKIE"]=> string(0) "" ["AUTH_PASSWORD"]=> string(0) "" ["AUTH_TYPE"]=> string(0) "" ["AUTH_USER"]=> string(0) "" ["CONTENT_LENGTH"]=> string(1) "0" ["CONTENT_TYPE"]=> string(0) "" ["PATH_TRANSLATED"]=> string(18) "c:\inetpub\wwwroot" ["QUERY_STRING"]=> string(0) "" ["REMOTE_ADDR"]=> string(9) "127.0.0.1" ["REMOTE_HOST"]=> string(9) "127.0.0.1" ["REMOTE_USER"]=> string(0) "" ["REQUEST_METHOD"]=> string(3) "GET" ["SERVER_NAME"]=> string(9) "localhost" ["SERVER_PORT"]=> string(2) "80" ["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1" ["SERVER_SOFTWARE"]=> string(17) "Microsoft-IIS/5.1" ["APPL_MD_PATH"]=> string(16) "/LM/W3SVC/1/ROOT" ["APPL_PHYSICAL_PATH"]=> string(19) "c:\inetpub\wwwroot\" ["INSTANCE_ID"]=> string(1) "1" ["INSTANCE_META_PATH"]=> string(11) "/LM/W3SVC/1" ["LOGON_USER"]=> string(0) "" ["REQUEST_URI"]=> string(9) "/ldap.php" ["URL"]=> string(9) "/ldap.php" ["SCRIPT_FILENAME"]=> string(27) "c:\inetpub\wwwroot/ldap.php" ["ORIG_PATH_INFO"]=> string(9) "/ldap.php" ["PATH_INFO"]=> string(0) "" ["ORIG_PATH_TRANSLATED"]=> string(27) "c:\inetpub\wwwroot\ldap.php" ["DOCUMENT_ROOT"]=> string(18) "c:\inetpub\wwwroot" ["PHP_SELF"]=> string(9) "/ldap.php" ["HTTP_ACCEPT"]=> string(3) "*/*" ["HTTP_ACCEPT_LANGUAGE"]=> string(5) "en-us" ["HTTP_CONNECTION"]=> string(10) "Keep-Alive" ["HTTP_HOST"]=> string(9) "localhost" ["HTTP_USER_AGENT"]=> string(164) "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Alexa Toolbar; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; MEGAUPLOAD 2.0)" ["HTTP_UA_CPU"]=> string(3) "x86" ["HTTP_ACCEPT_ENCODING"]=> string(13) "gzip, deflate" ["REQUEST_TIME"]=> int(1212053383) }
var_dump($_SERVER);
It didn't show any username = administrator
Maybe I'm missing something during the PHP setup with IIS. Like in JSP you need to append this string “request.tomcatAuthentication=false” in jk2.properties file in able not to receive null
in executing request.getRemoteUser() function. Is there same thing in PHP?
The output of var_dump($_SERVER);:
array(40) { ["ALL_HTTP"]=> string(322) "HTTP_ACCEPT:*/* HTTP_ACCEPT_LANGUAGE:en-us HTTP_CONNECTION:Keep-Alive HTTP_HOST:localhost HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Alexa Toolbar; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; MEGAUPLOAD 2.0) HTTP_UA_CPU:x86 HTTP_ACCEPT_ENCODING:gzip, deflate " ["HTTPS"]=> string(3) "off" ["SCRIPT_NAME"]=> string(9) "/ldap.php" ["HTTP_COOKIE"]=> string(0) "" ["AUTH_PASSWORD"]=> string(0) "" ["AUTH_TYPE"]=> string(0) "" ["AUTH_USER"]=> string(0) "" ["CONTENT_LENGTH"]=> string(1) "0" ["CONTENT_TYPE"]=> string(0) "" ["PATH_TRANSLATED"]=> string(18) "c:\inetpub\wwwroot" ["QUERY_STRING"]=> string(0) "" ["REMOTE_ADDR"]=> string(9) "127.0.0.1" ["REMOTE_HOST"]=> string(9) "127.0.0.1" ["REMOTE_USER"]=> string(0) "" ["REQUEST_METHOD"]=> string(3) "GET" ["SERVER_NAME"]=> string(9) "localhost" ["SERVER_PORT"]=> string(2) "80" ["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1" ["SERVER_SOFTWARE"]=> string(17) "Microsoft-IIS/5.1" ["APPL_MD_PATH"]=> string(16) "/LM/W3SVC/1/ROOT" ["APPL_PHYSICAL_PATH"]=> string(19) "c:\inetpub\wwwroot\" ["INSTANCE_ID"]=> string(1) "1" ["INSTANCE_META_PATH"]=> string(11) "/LM/W3SVC/1" ["LOGON_USER"]=> string(0) "" ["REQUEST_URI"]=> string(9) "/ldap.php" ["URL"]=> string(9) "/ldap.php" ["SCRIPT_FILENAME"]=> string(27) "c:\inetpub\wwwroot/ldap.php" ["ORIG_PATH_INFO"]=> string(9) "/ldap.php" ["PATH_INFO"]=> string(0) "" ["ORIG_PATH_TRANSLATED"]=> string(27) "c:\inetpub\wwwroot\ldap.php" ["DOCUMENT_ROOT"]=> string(18) "c:\inetpub\wwwroot" ["PHP_SELF"]=> string(9) "/ldap.php" ["HTTP_ACCEPT"]=> string(3) "*/*" ["HTTP_ACCEPT_LANGUAGE"]=> string(5) "en-us" ["HTTP_CONNECTION"]=> string(10) "Keep-Alive" ["HTTP_HOST"]=> string(9) "localhost" ["HTTP_USER_AGENT"]=> string(164) "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Alexa Toolbar; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 1.1.4322; MEGAUPLOAD 2.0)" ["HTTP_UA_CPU"]=> string(3) "x86" ["HTTP_ACCEPT_ENCODING"]=> string(13) "gzip, deflate" ["REQUEST_TIME"]=> int(1212053383) }
Re: PHP equivalent of request.getRemoteUser()
Guys please help
Is there something I missed during the PHP setup with IIS? Like in JSP you need to append this string “request.tomcatAuthentication=false” in jk2.properties file in able not to receive null in executing request.getRemoteUser() function. Is there same thing in PHP? Help is greatly appreciated.
Re: PHP equivalent of request.getRemoteUser()
Well, according this thread... http://www.jguru.com/faq/view.jsp?EID=842151 ...Tomcat and IIS only return the windows username if the server is set up to disallow anonymous access.. eg
If you've managed to set up your server to do that then I would imagine PHP's $_SERVER['REMOTE_USER'] would have the same information as it's just a way of accessing the HTTP AUTH username. How you'd set up your server to do that though, I can't help you with that. I'm not a sysadmin.If you use Tomcat with IIS as web server, it is possible to get the login name of the client by using getRemoteUser, if the client is running windows. In the IIS management console, go to the properties of the virtual directory "jakarta", select the security tab and press edit. Uncheck anonymous access and check integrated windows authentification. (How to configure IIS with tomcat is described somewhere else ...). Calling getRemoteUser now returns the clients windows login name.
Re: PHP equivalent of request.getRemoteUser()
Jedi Mod, it works! As in your quote, I just go to the properties of the "Default Website" in the IIS management console. In the security tab I uncheck anonymous access and check integrated windows authentification. The $_SERVER['REMOTE_USER'] contains the "administrator" Windows username. Thank very much for the kind support. 