如何确定URL是否在PHP中重定向? [英] How can I determine if a URL redirects in PHP?
本文介绍了如何确定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;
}
这篇关于如何确定URL是否在PHP中重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文