Description
array get_headers ( string url [, int format] )
get_headers() returns an array with the headers sent by
the server in response to a HTTP request. Returns
FALSE on failure and an error of level
E_WARNING will be issued.
If the optional format parameter is set to 1,
get_headers() parses the response and sets the array's
keys.
简单的说就是返回一个HTTP请求的头文件信息,格式如下:
【1】
Array ( [0] => HTTP/1.0 200 OK [1]
=> Server: nginx [2] => Date: Tue, 11
Dec 2012 02:55:22 GMT [3] => Content-Type:
image/jpeg [4] => Content-Length: 33595 [5]
=> Last-Modified: Fri, 09 Dec 2011 03:11:08 GMT [6]
=> Accept-Ranges: bytes [7] =>
Expires: Thu, 31 Dec 2037 23:55:55 GMT [8] =>
Cache-Control: max-age=315360000 [9] => X-Cache:
MISS [10] => X-Cache: MISS from
CT-ZJWZ-203-188.fastcdn.com [11] => Age: 82 [12]
=> X-Cache: HIT from CT-SHCB-169-11.fastcdn.com [13]
=> Connection: close )
【2】
Array ( [0] => HTTP/1.0 404 Not Found [1] => Server: nginx [2] => Date: Tue, 11 Dec 2012 03:06:19 GMT [3] => Content-Type: text/html [4] => Content-Length: 162 [5] => X-Cache: MISS from CT-ZJWZ-203-188.fastcdn.com [6] => X-Cache: MISS from CT-SHCB-169-11.fastcdn.com [7] => Connection: close )
我们可以使用里面的这些参数做很多优化。现在我就说与本文章有关的优化。就是使用页面的状态码。例如上面的1就是一个URL有效的返回。键名0所指向的键值很明显有个200,例2所显示的是404.我相信大家都懂的。接下来的我就不用多说了。大家都懂的。自由发挥吧。