How do I pause a page for a certain amount of seconds before redirecting the user to another HTML/PHP page using PHP?
Update: this works, but may not be the most appropriate solution for this situation. See comments.
Might this be what you are looking for?
<?php
sleep(5);
header("Location: http://www.example.com/");
exit();
?>
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.
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..)
never use sleep this way. Even under slight load your server will run out of http connections. Worst if your firewall runs out.
The delay parameter in the redirect header is made for exactly to the same reason.