How do I pause a page for a certain amount of seconds before redirecting the user to another HTML/PHP page using PHP?
The other 2 options are a Javascript redirect using setTimeout() or a meta refresh tag with a timeout.
Low-tech solution requiring no Javascript or even 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>
The advantage of this solution over using the "Location:" header is that you don't need to pause the script execution, which will appear to the user as if the server is busy or their connection has hung.
This solution also gives the user the option of proceeding to the new page immediately rather than having to wait x number of seconds while their browser displays no information.
Edit: I think it's also worth noting that if you do decide to use the the header() method, you need to make sure your sleep() duration isn't too long. I think most browsers generate a connection timed out after not receiving any data from the server for 1 minute.
If you want to wait and then go back to the previous page here's how
$referrer = $_SERVER['HTTP_REFERER'];
header ("Refresh: 2;URL='$referrer'");
This one should works:
<?php
header('Refresh: 5; URL=http://yoursite.com/page.php');
//other code
?>
and will allow your user to see whatever kind of output you want (You'll be redirected in X Seconds, click yere if dont, etc..)
Try:
<?php
$url=base_url().'page_you_want_to_go_to'
header('Refresh: X; URL=$url');
?>
This will give you additional flexibility when exchanging between localhost and remote server.
put this in the header.
<meta http-equiv="refresh" content="0.01;makensucces.html" />
on the place 0.01 you must put the seconds, i have used an decimal number.
and on the place of makensucces.html you need to put the name off the file you desire.