5

I am getting the client's (website user's) IP address. Now I'd like to go one step further by knowing the user's computer name. So far, my research has not turned up anything to aid me in retrieving this information.

Is it possible to use the user's IP address, or some other means, to get my visitor's computer name using PHP?

jprofitt
  • 10,874
  • 4
  • 36
  • 46
Anup Prakash
  • 14,406
  • 4
  • 17
  • 12
  • what do you mean under "name". Got any term? – Your Common Sense Jun 09 '10 at 05:59
  • What Basically u need to do with Computer Name here? telling us the requirement of using "COMPUTER NAME" we might help u in any other way to accomplish ur goal – OM The Eternity Jun 09 '10 at 07:06
  • Ok, Basically i want to keep information of user and their computer configuration for some survey purpose. I want to know, what is the percentage of user of different Operating system with hardware configuration. I want to mention this survey in my presentation. Hope knowing user information is not an illegal matter. – Anup Prakash Jun 09 '10 at 07:39

8 Answers8

5

PHP 5.4+

gethostbyaddr($_SERVER['REMOTE_ADDR'])
moeiscool
  • 1,318
  • 11
  • 14
  • This doesn't work in all cases. If the server is in internet and the visitor behind a router, you'll only get the hostname of the router, but not of the visitors computer. – netblognet May 08 '17 at 07:30
4

You can perform a reverse DNS lookup using gethostbyaddr().

Note that this will give you the name of the host the request came from according to reverse DNS.

  • It will not give you a result if reverse DNS isn't set up
  • It will not give you the Windows name of the computer
  • It will give you the name of the router if NAT is involved or proxy if a proxy is involved.
Matt
  • 74,352
  • 26
  • 153
  • 180
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
3

Not possible with plain php running on the server. It'd be a security/privacy issue to know details of the client such as computer name, mac address, contents of his drive.

You need some sort of application running on the client's machine in order to get this.

cherouvim
  • 31,725
  • 15
  • 104
  • 153
  • Exactly, I don't want to see his/her disk content or mac address. But i want to know just computer configuration(processor's GHz, Processor's name, RAM capacity) he/she is using(configuration) and the Operating System. – Anup Prakash Jun 09 '10 at 07:41
  • All of these are of similar importance (i.e private data, can be used to tell one user from other) and are not allowed by the http spec & implementers. You'd need some kind of signed applet or flash or activex component which would get those for you and send them to your server via http. This would definitely require the user's consent. – cherouvim Jun 09 '10 at 12:49
  • 1
    The operating system can be estimated via the http user agent string. – cherouvim Jun 09 '10 at 12:50
  • You can force the browser to send the client's computer name via NTLM to the server, which then can be read by the PHP script: http://stackoverflow.com/a/43842041/251719 Maybe not the most easy way, but it is possible at all. – netblognet May 08 '17 at 07:32
3

If you're referring to the hostname (displayed for instance by the hostname command on linux) of the computer doing the request:

That information is not included in an HTTP request. (That is, it's impossible for PHP to figure out.)

You could do a reverse DNS lookup, but that's probably not what you want anyway.

aioobe
  • 413,195
  • 112
  • 811
  • 826
3

This is all that you could get using just PHP (you may try these butIi dont think this is what you actually needed):

gethostname()
gethostbyname(gethostname())
$_SERVER['HTTP_HOST']
$_SERVER['SERVER_SIGNATURE']
$_SERVER['SERVER_NAME']
$_SERVER['SERVER_ADDR']
$_SERVER['SERVER_PORT']
$_SERVER['REMOTE_ADDR']
gethostbyaddr($_SERVER['REMOTE_ADDR'])
php_uname()
Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
0

The only thing you could do is try to get a DNS name for the client. "Computer Name" is a Windows made-up thing. Just call the built-in function gethostbyaddr() with the client's IP address. However, it won't always (hardly ever) work.

Eric Mickelsen
  • 10,309
  • 2
  • 30
  • 41
0

You can do this by

$_SERVER['REMOTE_HOST']

'REMOTE_HOST' - The Host name from which the user is viewing the current page. The reverse dns lookup is based off the REMOTE_ADDR of the user.

Note: Your web server must be configured to create this variable. For example in Apache you'll need HostnameLookups On inside httpd.conf for it to exist. As David mentioned you can also use . gethostbyaddr()

Pls go thru all the comments in the url before actually using the function.

indianwebdevil
  • 4,879
  • 7
  • 37
  • 51
  • Yes! I saw it in php manual. but it doesn't work. So, do you have any other option to see the name of client computer. – Anup Prakash Jun 09 '10 at 08:16
-3

Do something lik this:

     <?php
 //get host by name
 echo gethostname();
 echo "<br>";
 //get OS
 echo php_uname();
 ?>
Hamid
  • 21
  • 5