如何确定 URL 是否在 PHP 中重定向?
我看到有人问了一个关于检测 URL 是否从 groovy 和 perl 重定向但在 PHP 上找不到任何内容的问题.
I saw someone ask a question about detecting if a URL redirects from groovy and perl but couldn't find anything on PHP.
有人知道我可以在什么地方找到执行此操作的代码吗?
Anyone know of somewhere I could find that code that does this?
推荐答案
实际上,我发现这最有效:
Actually, I found this works best:
function GetURL($URL)
{
$ch = curl_init($URL);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
return $code;
}
相关文章