输入banner图图片脚本导航/分类

将百度搜索结果链接转为实际链接

最近百度动作挺大的,搜索算法频繁调整。刚才在分析本站百度收录情况的时候又发现百度的搜索结果连接竟然也变了,想必这么做是对付360恶意抓取百度的搜索结果的吧。没办法,百度变了,俺这收录分析工具也得跟着变一变了,总得将这奇长无比的链接转为正常的链接才行吧!

研究了一下,发现还是可以转变的。

function getRealUrl($url){

$header=get_headers($url,1);
if (strpos($header[0],'301')||strpos($header[0],'302')){
if(is_array($header['Location'])){
return $header['Location'][count($header['Location'])-1];
}else{
return $header['Location'];
}
}else{
return $url;
}
}例如下面这个例子:header('Content-type:text/html;charset=utf-8');
function getRealUrl($url){
$header=get_headers($url,1);
if (strpos($header[0],'301')||strpos($header[0],'302')){
if(is_array($header['Location'])){
return $header['Location'][count($header['Location'])-1];
}else{
return $header['Location'];
}
}else{
return $url;
}
}
$url='http://www.baidu.com/link?url=nuQ4reDIkrTCHpWQQXJpTC_GSLEUrk6Bb6WmCMZqaLHES2LUiv98OaiKZjvjz8xx';

$url=getRealUrl($url);
echo '真实的url为:'.$url;