转 php获取链接跳转的真实地址
$url = 'http://www.chawen.org';
$headers = get_headers($url, TRUE);
// print_r($headers);die;
//输出跳转到的网址
if(isset($headers['Location'])){
echo $headers['Location'];
}elseif(isset($headers['location'])){
echo $headers['location'];
}else{
echo 'not get';
}
下面这个是网上找到的 https://blog.csdn.net/liuxin_0725/article/details/89889151
echo get_redirect_url('http://www.baidu.com');
function get_redirect_url($url){
$redirect_url = null;
$url_parts = @parse_url($url);
if (!$url_parts) return false;
if (!isset($url_parts['host'])) return false; //can't process relative URLs
if (!isset($url_parts['path'])) $url_parts['path'] = '/';
$sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);...