get_headers:發送服務器響應HTTP請求
get_headers(字符串url[鏈接格式])
get_headers()以數組的形式返回服務器HTTP請求。如果執行失敗,將返回FALSE和一個錯誤的水平E_WARNING》。
可選參數設置為1,get_headers()能分析系統的響應速度和集數組中的鍵。
注意:使用該函數需要把 php.ini裡面的allow_url_fopen = On,才能使用。
實例如下:
<?php
$url = http://www.ite5e.com;
print_r(get_headers($url));
print_r(get_headers($url, 1));
?>
打印結果:
Array
(
[0] => HTTP/1.1 200 OK
[1] => Connection: close
[2] => Date: Tue, 16 Nov 2010 09:48:20 GMT
[3] => Content-Length: 52708
[4] => Content-Type: text/html
[5] => Content-Location: http://www.ite5e.com/index.html
[6] => Last-Modified: Tue, 16 Nov 2010 09:19:13 GMT
[7] => Accept-Ranges: bytes
[8] => ETag: "50d16c556f85cb1:b1f76"
[9] => Server: Microsoft-IIS/6.0
[10] => X-Powered-By: ASP.NET
)
Array
(
[0] => HTTP/1.1 200 OK
[Connection] => close
[Date] => Tue, 16 Nov 2010 09:48:21 GMT
[Content-Length] => 52708
[Content-Type] => text/html
[Content-Location] => http://www.ite5e.com/index.html
[Last-Modified] => Tue, 16 Nov 2010 09:19:13 GMT
[Accept-Ranges] => bytes
[ETag] => "50d16c556f85cb1:b1f76"
[Server] => Microsoft-IIS/6.0
[X-Powered-By] => ASP.NET
)