我有以下
PHP代码,我想添加延迟:
<?PHP echo "Message has been sent."; header("Location: page2.PHP",true,303); exit; ?>
上面的代码发生得太快,所以我看不到消息:
我试过了:
<?PHP sleep(5); echo "Message has been sent."; header("Location: page2.PHP",303); exit; ?>
这也没有显示消息,但它会睡5秒钟,这只是浪费时间.
您无法通过HTTP位置重定向执行此操作,因为只要浏览器获得标头,就会发生此重定向.而是在标头中使用刷新重定向:
原文链接:https://www.f2er.com/php/136728.htmlheader( "Refresh:5; url=http://www.example.com/page2.PHP",303);
这应该适用于现代浏览器,但它不是标准化的,所以要获得相同的功能,请使用元刷新重定向(意味着您还必须输出完整的HTML):
<Meta http-equiv="refresh" content="5;url=http://www.example.com/page2.PHP">
Used in redirection,or when a new resource has been created. This refresh redirects after X seconds. This is a proprietary,non-standard header extension introduced by Netscape and supported by most web browsers.