這樣做的一種方法是使用PHP的get_headers()函數返回網絡服務器資源ponse頭
$url = 'http://php.net';
print_r(get_headers($url));
將返回
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
)
,你可以看到你有server
頭,告訴你,他們正在運行nginx/1.6.2
,或者你可以在第二個參數添加到函數這將返回所有已解析的標頭
$url = 'http://php.net';
$headers = get_headers($url, 1);
echo $headers['Server']; //ngnix/1.6.2
你試過$ _SERVER ['SERVER_SOFTWARE']和$ _SERVER ['SERVER_SIGNATURE']嗎? – trainoasis
是的,這給了我我的本地Web服務器名稱(工作正常)..但是,我想要獲得遠程主機,而不是我自己的Web服務器名稱。我不認爲我應該使用$ _SERVER,因爲這是僅用於本地服務器 – user3436467