现在很多网站都有在用Url跳转,地址加密,很多时候我们需要需要抓取到他跳转的真是地址,下面这个方法还是不错的。

function curl_post_302($url,$data=null) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 获取转向后的内容 
    $data = curl_exec($ch);
    $Headers = curl_getinfo($ch); 
    curl_close($ch);
    if($data != $Headers){ 
        return $Headers["url"]; 
        }else{
            return false;
        }
}