PHP通过301与302的Http状态获取真实URL地址
How to Get Real Url by 301 or 302 Http Statuses in PHP
2021-06-15 10:22:37
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;
}
}