PHP获取网址301重定向跳转后的网址

180it 2021-09-03 PM 1454℃ 0条

PHP获取网址301重定向跳转后的网址

源码:

function get301URL($url){
    $header = get_headers($url,1);
    if (strpos($header[0],'301') || strpos($header[0],'302')) {
        if(is_array($header['Location'])) {
            return $header['Location'][count($header['Location'])-1];
        }else{
            return $header['Location'];
        }
    }else {
        return $url;
    }
}
使用方法示例:

get301URL("http://4asport.com");
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

PHP获取网址301重定向跳转后的网址