I have the following php code which I want to add a delay too:
<?php
echo "Message has been sent.";
header("Location: page2.php", true, 303);
exit;
?>
The above code happens too fast so I can’t see the message:
I have tried:
<?php
sleep(5);
echo "Message has been sent.";
header("Location: page2.php", true, 303);
exit;
?>
This doesn’t display the message either, but it does sleep for 5 seconds, which is just a waste of time.
How do I get it to display a message for 5 second before redirecting?
You cannot do this with a HTTP location redirect, as this redirect will happen as soon as the browser gets the header. Instead, use a refresh redirect in the header:
This should work on modern browsers, however it is not standardized, so to get the equivalent functionality would be do use a meta refresh redirect (meaning you’d have to output a full HTML too):
From the Wikipedia page: