PHP sleep()在重定向中没有像我希望的那样工作


PHP sleep() not working how i'd hoped in redirect

我有一个表单,它在提交时检查数据。如果数据无效,我当前让它回显文本。

我想让它回显文本,然后暂停和重定向。

我试过sleep();但是这会导致页面在提交时休眠,等待x秒,然后继续而不显示echo的

知道怎么绕过这个吗

正常发送错误消息,并在x秒后使用元刷新进行重定向:

<?php
// your code that determines there is an error goes here
header('Refresh: 10;url=your_page.php');
echo $errorMessage;

header()调用与此元标记相同:

<meta http-equiv="refresh" content="10;URL='your_page.php'">

一个简单的解决方案是输出元刷新,作为在一段时间后重定向用户的一种手段。(在下面的例子中是5秒)

<meta http-equiv="refresh" content="5;URL='http://dest.url/whereever/'">

就像其他元标签一样,位于HTML头部。

相关文章: