3

I was wondering if it was possible to get the username of the person who had logged on to the computer in php or javascript. For example, if I get on my laptop, log in to the computer, and go to the website, I would want it to show the name I logged in with.

Is there any way to do this, or is it impossible

scrblnrd3
  • 7,228
  • 9
  • 33
  • 64
  • Do you mean the username of the website you logged in to, or the username of your Windows/Mac/Linux name? – paddotk Mar 27 '13 at 18:57

5 Answers5

4

That's not possible with PHP or Javascript.

You can look at the headers sent to the server to see what data is sent (getallheaders).

As others suggest you can use plugins that integrate more tightly with the host computer to get this information.

Matt Zeunert
  • 16,075
  • 6
  • 52
  • 78
0

PHP is server side, you will have to use a PHP webserver plugin like active directory. But the user will have to authenticate with your site, you cannot just 'pull it'

LDAP example:
Authenticating in PHP using LDAP through Active Directory

Community
  • 1
  • 1
Jakub
  • 20,418
  • 8
  • 65
  • 92
0

Actually it is possible if you have the Apache NTLM module. But you would have to be able to install it on your server. So if it is a hosted box, probably not going to work. Downside, I think it only works with IE.

NTLM is an authentication protocol used by Microsoft Internet Informations Server(tm) and Microsoft Internet Explorer(tm). While it is not really secure, it offers background authentication (the workstation logon credentials of users are passed through to the web server). This feature is widely used in intranets based on these Microsoft products.

http://modntlm.sourceforge.net/

user-44651
  • 3,924
  • 6
  • 41
  • 87
0

PHP is a server-side scripting engine and it knows nothing about the client except for what browser sends to the server, but username isn't there.

Same with JavaScript - this one operates client-side, but sharing username with webpages could be a serious security flaw. Websites should be kept away from any user-sensitive data.

And finally, some systems may not implement any user profiles (like mobile phones and smartphones). What would be sent then?

gronostaj
  • 2,231
  • 2
  • 23
  • 43
0

if it is just the login (user ID):

<?php echo filter_input(INPUT_SERVER, 'LOGON_USER'); ?>

which is the same as

<?php echo $_SERVER['LOGON_USER']; ?>

you also could use

<?php

foreach ($_SERVER as $var => $value){
    
    echo "$var => $value<br />";
    
}

?>

to show all the possible values for the superglobal $_SERVER avaible in your server or localhost.