Str*_*rae 35
这个应该工作:
<?php
header('Refresh: 5; URL=http://yoursite.com/page.php');
//other code
?>
Run Code Online (Sandbox Code Playgroud)
并允许您的用户看到您想要的任何类型的输出(您将被重定向到X秒,如果不等,请点击,等等.)
Cal*_*vin 15
不需要Javascript甚至PHP的低技术解决方案:
<html>
<head>
<title>Redirecting...</title>
<meta http-equiv="refresh"
content="10;URL=http://www.newsite.com">
</head>
<body>
You are being automatically redirected to a new location.<br />
If your browser does not redirect you in 10 seconds, or you do
not wish to wait, <a href="http://www.newsite.com">click here</a>.
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
此解决方案优于使用"Location:"标头的优点是您不需要暂停脚本执行,这对用户来说就像服务器正忙或连接已挂起一样.
此解决方案还为用户提供了立即进入新页面的选项,而不是在浏览器不显示任何信息时等待x秒.
编辑:我认为值得注意的是,如果你决定使用header()方法,你需要确保你的sleep()持续时间不会太长.我认为大多数浏览器在没有从服务器接收任何数据1分钟后生成连接超时.
小智 5
如果您想等待然后返回上一页,请按以下步骤操作
$referrer = $_SERVER['HTTP_REFERER'];
header ("Refresh: 2;URL='$referrer'");
Run Code Online (Sandbox Code Playgroud)
更新:这可行,但可能不是这种情况的最合适的解决方案。看评论。
这可能就是您正在寻找的东西吗?
<?php
sleep(5);
header("Location: http://www.example.com/");
exit();
?>
Run Code Online (Sandbox Code Playgroud)