2

这是我的尝试:

@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

如您所见,“3秒”是无法控制的,如何让它在3秒内生效?

4

3 回答 3

5

最简单的方法是使用meta重定向或 javascript 重定向。说您如何提供文本/html,您可以将其中任何一个回显到浏览器。

<meta http-equiv="refresh" content="3;URL=/newpage.php">

或者

window.setTimeout(function() { window.location = '/newpage.php' }, 3000);

编辑:根据关于URL 重定向的 Wikipedia 页面,您可以将Refresh标头从 PHP 直接发送到浏览器。不知道浏览器对此的支持程度如何。

header('Refresh: 3; url=/newpage.php');
于 2009-06-30T20:10:05.350 回答
4

这应该在 PHP 中起作用:

header('Refresh: 3; url=index.php');
于 2009-06-30T20:11:42.337 回答
0

您可以利用刷新元标记,如下所示:

<html> 
<head> 
    <title>redirect page</title> 
    <META http-equiv="refresh" content="5;URL=http://www.newurl.com"> 
</head> 
<body bgcolor="#ffffff"> 
    The contents you are looking for have moved. 
    You will be redirected to the new location automatically in 5 seconds.
</body>
</html>
于 2009-06-30T20:12:08.683 回答