I have the following dumb code:
<?
echo "<html><br><br><br><div id='loading'><p><img src='loader.gif'> Please wait 6 seconds...</p></div></html>";
sleep(6);
header('Location: http://google.com/');
?>
Why doesn’t the HTML piece of code show up in the browser before sleeping 6 seconds and then redirecting? The codes doesn’t output the HTML code at all, waits 6 seconds then sends me to the location. What do I do wrong?
You would need to do something like (this won’t work):
However: This won’t work as expected, you cannot redirect the browser after sending content (PHP will throw and error and tell you this)
Instead you should:
Where the
<meta http-equiv="refresh" content="6;URL='http://YOURURL.com/'">tag is an HTML tag to tell the browser to change to the provided url after 6 secondsTo avoid adding the meta tag, you could also do this:
But to be safe you should add both the header and the meta tag!