Get the client's computer name

后端 未结 8 1277
轮回少年
轮回少年 2020-12-20 23:47

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 any

相关标签:
8条回答
  • 2020-12-21 00:25

    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.

    0 讨论(0)
  • 2020-12-21 00:25

    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.

    0 讨论(0)
  • 2020-12-21 00:29

    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()
    
    0 讨论(0)
  • 2020-12-21 00:29

    Do something lik this:

         <?php
     //get host by name
     echo gethostname();
     echo "<br>";
     //get OS
     echo php_uname();
     ?>
    
    0 讨论(0)
  • 2020-12-21 00:44

    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.

    0 讨论(0)
  • 2020-12-21 00:45

    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.

    0 讨论(0)
提交回复
热议问题