如何在PHP中3秒内切换到另一个页面?

omg*_*omg 1 php refresh

这是我的尝试:

@header("Content-type: text/html; charset=utf-8");
@header("Location:/index.php");
@header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
@header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
Run Code Online (Sandbox Code Playgroud)

如您所见,无法控制"3秒",如何让它在3秒内生效?

tj1*_*111 5

最简单的方法是使用meta重定向或javascript重定向.说你如何提供text/html,你可以将这些中的任何一个回显给浏览器.

<meta http-equiv="refresh" content="3;URL=/newpage.php">
Run Code Online (Sandbox Code Playgroud)

要么

window.setTimeout(function() { window.location = '/newpage.php' }, 3000);
Run Code Online (Sandbox Code Playgroud)

编辑:根据URL重定向的维基百科页面,您可以Refresh从PHP直接将标头发送到浏览器.虽然没有关于浏览器如何支持这一点的线索.

header('Refresh: 3; url=/newpage.php');
Run Code Online (Sandbox Code Playgroud)


Geo*_*orn 5

在 PHP 中这应该可以工作:

header('Refresh: 3; url=index.php');
Run Code Online (Sandbox Code Playgroud)