How to identify the web server name of a remote host
According to this solution the link it shows how to get the webserver name for the local webserver, but how to do the same for the remote server from the url?
i.e. $_SERVER['software']
returns type name Apache / 2.2.21 (Win32) PHP / 5.3.10
how can i apply this solution for remote server - example here: http://browserspy.dk/webserver.php
I want to be able to specify the name of the remote server, i.e. $url = 'www.domain.com';
- I want to get the webserver name as shown above for the hostname given in$url
I am only interested in the name of the web server
source to share
One way to do this is to use the PHP get_headers ( ) function , which returns the response headers of the web servers
$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 a header server
that tells you what they are runningnginx/1.6.2
or you can add a second parameter to the function which will return all parsed headers allready
$url = 'http://php.net';
$headers = get_headers($url, 1);
echo $headers['Server']; //ngnix/1.6.2
source to share