获取302跳转后的 URL

<?php
$url = 'http://api.t.sina.com.cn/1410797647/statuses/9814935883';
 
function get302($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
    curl_exec($ch);
    $new_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    curl_close($ch);
 
    return $new_url;
}
 
$new_url = get302($url);
echo $new_url;
snippets/get302url.txt · 最后更改: 2011/04/29 03:40 由 lostsnow
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki