How do I pause a page for a certain amount of seconds before redirecting the user to another HTML/PHP page using PHP?
We can use the sleep() method of PHP along with the above method to delay redirect for a few seconds. If we need to wait, users for 5 or 10 seconds we just need to use sleep(5) or sleep(10) before the header method.
You can try this: header('Refresh: 10; URL=http://yoursite.com/page.php'); Where 10 is in seconds.
If you need to pause the execution of your PHP script for times shorter than a second, you will need to use the usleep() function. With this function, you can specify the number of microseconds you want the script to sleep. A microsecond is one-millionth of a second.
The sleep() function delays execution of the current script for a specified number of seconds. Note: This function throws an error if the specified number of seconds is negative.
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..)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With