Mobile app version of vmapp.org
Login or Join
Holmes151

: How to make a program that display something and after 10 seconds automatically redirect to another site? <?php echo "Hello World"; sleep(10); header("Location: " . "http://google.com");

@Holmes151

Posted in: #GoogleSearchConsole

<?php
echo "Hello World";
sleep(10);
header("Location: " . "http://google.com");
?>


The problem with this is that header is already sent

Warning: Cannot modify header information - headers already sent by (output started at /home2/provenda/public_html/silverslady.com/index.php:46) in /home2/provenda/public_html/silverslady.com/index.php on line 75

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Holmes151

2 Comments

Sorted by latest first Latest Oldest Best

 

@Miguel251

Here is 2 ways to do this:

<?php
echo '<meta http-equiv="refresh" content="10; url=http://example.com/">';
?>


or

<?php
header("refresh:10;url=http://example.com");
?>


I'd recommend the second option.

About the "headers already sent"-error. That is commonly know as "the whitespace problem". Here is an exceptionally good response concerning the subject: stackoverflow.com/a/8028987/668236

10% popularity Vote Up Vote Down


 

@BetL925

You can use only HTML to do this by using the meta refresh like this:

<meta http-equiv="refresh" content="10; url=http://redirectedurl.com/">


redirectedurl.com is the new URL you want redirect to afeter 10 seconds.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme