可以的getheader<?php
$url = 'http://www.example.com';print_r(get_headers($url));print_r(get_headers($url, 1));
?>
$url = 'http://www.example.com';print_r(get_headers($url));print_r(get_headers($url, 1));
?>
调试欢乐多
$url = 'http://www.csdn.net';print_r(get_headers($url));print_r(get_headers($url, 1));
?>
执行结果[code=BatchFile]Array
(
[0] => HTTP/1.0 200 OK
[1] => Cache-Control: max-age=1800
[2] => Content-Length: 158020
[3] => Content-Type: text/html
[4] => Content-Location: http://www.csdn.net/index.htm
[5] => Last-Modified: Mon, 15 Dec 2008 09:51:09 GMT
[6] => Accept-Ranges: bytes
[7] => ETag: W/"9ee933a89a5ec91:697"
[8] => Server: Microsoft-IIS/6.0
[9] => X-Powered-By: ASP.NET
[10] => Date: Mon, 15 Dec 2008 11:10:42 GMT
[11] => Age: 20
[12] => X-Cache: HIT from longrujun.name
[13] => X-Cache-Lookup: HIT from longrujun.name:80
[14] => Via: 1.0 cache4.longrujun.name:80 (Longrujun)
[15] => Connection: close
)
Array
(
[0] => HTTP/1.0 200 OK
[Cache-Control] => max-age=1800
[Content-Length] => 158020
[Content-Type] => text/html
[Content-Location] => http://www.csdn.net/index.htm
[Last-Modified] => Mon, 15 Dec 2008 09:51:09 GMT
[Accept-Ranges] => bytes
[ETag] => W/"9ee933a89a5ec91:697"
[Server] => Microsoft-IIS/6.0
[X-Powered-By] => ASP.NET
[Date] => Mon, 15 Dec 2008 11:10:42 GMT
[Age] => 21
[X-Cache] => HIT from longrujun.name
[X-Cache-Lookup] => HIT from longrujun.name:80
[Via] => 1.0 cache4.longrujun.name:80 (Longrujun)
[Connection] => close
)[/code]
$url = 'http://www.example.com';
$result=get_headers($url);
?>则返回的是普通数组,判断服务器软件是判断数组的$result[3](第三个元素)
如果执行的是数组<?php
$url = 'http://www.example.com';
$result=get_headers($url, 1);
?>则返回的是字母索引的数组,判断服务器软件是判断数组的$result['Server'](也是第三个元素)