Home  >  Article  >  php教程  >  php获取网页301真实地址

php获取网页301真实地址

PHP中文网
PHP中文网Original
2016-05-25 17:09:451478browse

PHP代码

function getrealurl($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;
    }
}

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn