tags:

views:

260

answers:

3

Here is my try:

@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

As you have seen,there is no control over "3 seconds",how to make it take effect in 3 seconds?

+5  A: 

The easiest way to do this is to use a meta redirect or a javascript redirect. Saying as how you are serving text/html, you can echo either of these to the browser.

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

or

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

Edit: According to the Wikipedia page on URL redirection you can send the Refresh header directly to the browser from PHP. No clue on how well browsers support this though.

header('Refresh: 3; url=/newpage.php');
tj111
+1 ...............
Aiden Bell
I remember seeing a PHP function that would output both. Don't really need to go hunt it down - the Asker could implement that.
Jonathan Sampson
I think your parameters are mixed up on the setTimeout...
Jonathan Sampson
@Jonathan: Thanks, fixed.
tj111
no,i need it to be done in pure php,not html
Shore
+2  A: 

This should work, in PHP:

header('Refresh: 3; url=index.php');
gclaghorn
how is this supported by different browsers?
Shore
AFAIK, it's supported by all major browsers.
gclaghorn
Just note that this code has to come before any other php code on the page.
gclaghorn
A: 

You could take advantage of the refresh meta tag, like this:

<html> 
<head> 
    <title>redirect page</title> 
    <META http-equiv="refresh" content="5;URL=http://www.newurl.com"&gt; 
</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>
gahooa