php获取header[‘location’]信息常见问题



//初始化url信息
$host= “http://www.tudou.com/”;

$url=$host.”l/rzTf7ap2viw/&iid=222004556&resourceId=0_04_05_99/v.swf”;

//按照键名获取header响应信息
$headers = get_headers($url, TRUE);

//获取这个土豆的302跳转地址
$u302= $headers[“Location”];

正常情况下,的高级别apache和php版本 获取这个location是没有问题的,但是因为版本的问题,有部分低版本,无法正常返回location信息,其他信息正常,测试其他跳转url,正常返回location信息。究其原因,主要是location过长导致的。如下:

http://js.tudouui.com/bin/player2/olc_8.swf?iid=132355102&swfPath=http://js.tudouui.com/bin/lingtong/SocialPlayer_148.swf&youkuId=XODgxOTM5MDAw&vcode=XODgxOTM5MDAw&lshare=1&listOwner=460446025&tvcCode=-1&tag=null&title=%E9%82%A3%E4%BA%9B%E5%B9%B4%E4%B8%8EDr.%E9%AD%8F%E7%BF%BB%E8%84%B8%E8%BF%87%E7%9A%84%E8%AF%84%E5%A7%94&mediaType=vi&totalTime=225470&hdType=3&hasPassword=0&nWidth=-1&isOriginal=0&channelId=31&nHeight=-1&banPublic=false&videoOwner=460446025&videoOwner=460446025&ocode=pdyocYRfWoc&tict=3&is1080p=0&hasWaterMark=0&totalTime=225470&channelId=31&cs=&k=&code=a9rf5GDdhhU&panelRecm=http://css.tudouui.com/bin/lingtong/PanelRecm_9.swz&panelDanmu=http://css.tudouui.com/bin/lingtong/PanelDanmu_18.swz&panelEnd=http://css.tudouui.com/bin/lingtong/PanelEnd_13.swz&pepper=http://css.tudouui.com/bin/binder/pepper_17.png&panelShare=http://css.tudouui.com/bin/lingtong/PanelShare_7.swz&panelCloud=http://css.tudouui.com/bin/lingtong/PanelCloud_12.swz&autoPlay=false&listType=1&rurl=&resourceId=0_04_05_99&autostart=false&lid=21537817&lCode=NaeTFum4PsY&snap_pic=http%3A%2F%2Fr1.ykimg.com%2F0541040854C9B0FE6A0A4E14293159E1&aopRate=0.01&p2pRate=0.95&adSourceId=99999&yjuid=null&yseid=1422598983263d9LR4n&yseidtimeout=1422629597814&yseidcount=2&uid=null&juid=0191ummk6k17lc&vip=0

另外还有部分服务器版本存在直接截断的问题,就是显示这个url地址不完整。会把余下的location信息存储到下一个header的键值中,这个可以测试输出可见。所以尝试输出的时候 可以考虑合并处理 例如

$u302=$header[10].$header[11];

其他的一些hader信息获取普通方法网上有很多,这里就不再介绍了。