所以我有一个代码:PHP,抓重定向
function testMe ($redir)
{
if ($redir)
{
header ('Location: /');
}
}
我想如果它使用重定向来测试这个功能,但我不知道如何抓住它。它像捕获异常
编辑:所以我想如果header()
wasnt写,但知道这是调用
所以我有一个代码:PHP,抓重定向
function testMe ($redir)
{
if ($redir)
{
header ('Location: /');
}
}
我想如果它使用重定向来测试这个功能,但我不知道如何抓住它。它像捕获异常
编辑:所以我想如果header()
wasnt写,但知道这是调用
//calling the function which somewhere does this
header('Location: /');
//testing
foreach (headers_list() as $header) {
if (strpos($header, 'Location:') !== false) {
//header location set, function works, removing the set header
header_remove('Location');
}
}
我明白了。现在我只是不明白为什么在header()函数后执行任何代码... – 2014-09-23 21:56:54
为什么不呢?你还没有阻止它。如果你在header()调用之后放置die(),那么它将不会继续。 – Weltschmerz 2014-09-23 21:59:25
你的意思是你想不重定向有时? 'header'应该始终有效,你能否更清楚你的问题? – danronmoon 2014-09-23 21:00:44
是的,我想“取消”重定向。 – 2014-09-23 21:01:26