获取链接最终跳转地址的PHP代码
<?php
$url = $_GET['url'];
$url = str_replace(' ','%20',$url);
$url = str_replace(':','%3A',$url);
$url = str_replace('%3A//','://',$url);
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;
}
}
echo getrealurl($url);
在传递get参数时,&写为%26