function getrealurl($url){
    $realurl = $url;
    try {
        $headers = get_headers($realurl, true);
        if(isset($headers['Location'])){
            if(is_array($headers['Location'])){
                $location = '';
                for($i=count($headers['Location']); $i>0; $i--){
                    $location = $headers['Location'][$i-1] . $location;
                    if (preg_match("/^(http|https)\:\/\//i", $location)) {
                        break;
                    }
                }
                $realurl = $location;
            }else{
                if (!preg_match("/^(http|https)\:\/\//i", $headers['Location'])) {
                    $realurl .= $headers['Location'];
                }else{
                    $realurl = $headers['Location'];
                }
            }
        }
    } catch (Exception $e) {
    }
    return $realurl;
}

达西先生
1 声望0 粉丝