php get header url,php get_headers 如何判断URL是否真实有效

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.我相信大家都懂的。接下来的我就不用多说了。大家都懂的。自由发挥吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值