当前位置 : 主页 > 网络编程 > PHP >

php 获取跳转的Url真实地址

来源:互联网 收集:自由互联 发布时间:2021-07-03
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(
 
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;
        }
}

网友评论