简体   繁体   中英

how to identify the web server name of remote host

According to this solution link it shows how to get the web server name for a local web server but how to do the same for a remote server by URL ?

ie $_SERVER['software'] returns name like Apache/2.2.21 (Win32) PHP/5.3.10

how can I apply this solution for a remote server - example here: http://browserspy.dk/webserver.php

I want to be able to specify the name of the remote server ie $url = 'www.domain.com'; - I want to get the web server name as shown above for host name specified in $url

I am only interested in the web server name

One method of doing this is using PHP's get_headers( ) function which return the web-servers response headers

$url = 'http://php.net';
print_r(get_headers($url));

which will return

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Server: nginx/1.6.2
    [2] => Date: Fri, 08 May 2015 13:21:44 GMT
    [3] => Content-Type: text/html; charset=utf-8
    [4] => Connection: close
    [5] => X-Powered-By: PHP/5.6.7-1
    [6] => Last-Modified: Fri, 08 May 2015 13:10:12 GMT
    [7] => Content-language: en
    [8] => X-Frame-Options: SAMEORIGIN
    [9] => Set-Cookie: COUNTRY=NA%2C95.77.98.186; expires=Fri, 15-May-2015 13:21:44 GMT; Max-Age=604800; path=/; domain=.php.net
    [10] => Set-Cookie: LAST_NEWS=1431091304; expires=Sat, 07-May-2016 13:21:44 GMT; Max-Age=31536000; path=/; domain=.php.net
    [11] => Link: <http://php.net/index>; rel=shorturl
    [12] => Vary: Accept-Encoding
)

as you can see you have the server header which tells you that they are running nginx/1.6.2

or you can add the second parameter to the function which will return the allready parsed headers

$url = 'http://php.net';
$headers = get_headers($url, 1);
echo $headers['Server']; //ngnix/1.6.2

trainoasis is right, you can use :

$_SERVER['SERVER_SOFTWARE']

OR

$_SERVER['SERVER_SIGNATURE']

OR

gethostbyaddr($_SERVER['REMOTE_ADDR']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM