Page redirect after certain time PHP

PhpRedirect

Php Problem Overview


There is a certain PHP function for redirecting after some time. I saw it somewhere but can't remember. It's like the gmail redirection after logging in. Please, could anyone remind me?

Php Solutions


Solution 1 - Php

header( "refresh:5;url=wherever.php" );

this is the php way to set header which will redirect you to wherever.php in 5 seconds


> Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file. (source php.net)

Solution 2 - Php

You can use javascript to redirect after some time

setTimeout(function () {
   window.location.href= 'http://www.google.com'; // the redirect goes here
   
},5000); // 5 seconds

Solution 3 - Php

You can try this:

header('Refresh: 10; URL=http://yoursite.com/page.php');

Where 10 is in seconds.

Solution 4 - Php

you would want to use php to write out a meta tag.

<meta http-equiv="refresh" content="5;url=http://www.yoursite.com">

It is not recommended but it is possible. The 5 in this example is the number of seconds before it refreshes.

Solution 5 - Php

header( "refresh:5;url=wherever.php" );

indeed you can use this code as teneff said, but you don't have to necessarily put the header before any sent output (this would output a "cannot relocate header.... :3 error").

To solve this use the php function ob_start(); before any html is outputed.

To terminate the ob just put ob_end_flush(); after you don't have any html output.

cheers!

Solution 6 - Php

The PHP refresh after 5 seconds didn't work for me when opening a Save As dialogue to save a file: (header('Content-type: text/plain'); header("Content-Disposition: attachment; filename=$filename>");)

After the Save As link was clicked, and file was saved, the timed refresh stopped on the calling page.

However, thank you very much, ibu's javascript solution just kept on ticking and refreshing my webpage, which is what I needed for my specific application. So thank you ibu for posting javascript solution to php problem here.

You can use javascript to redirect after some time

setTimeout(function () {    
    window.location.href = 'http://www.google.com'; 
},5000); // 5 seconds

Solution 7 - Php

If you are redirecting with PHP, then you would simply use the sleep() command to sleep for however many seconds before redirecting.

But, I think what you are referring to is the meta refresh tag:

http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm

Solution 8 - Php

You can use this javascript code to redirect after a specific time. Hope it will work.

setRedirectTime(function () 
{
   window.location.href= 'https://www.google.com'; // the redirect URL will be here

},10000); // 10 seconds

Solution 9 - Php

Redirect PHP time programming:

 <?php
 header("Refresh:10;url=***-----índex.php--OR----URL-----");
 ?>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionafaolekView Question on Stackoverflow
Solution 1 - PhpTeneffView Answer on Stackoverflow
Solution 2 - PhpIbuView Answer on Stackoverflow
Solution 3 - PhproyruiView Answer on Stackoverflow
Solution 4 - PhpJohnView Answer on Stackoverflow
Solution 5 - PhpJJJackView Answer on Stackoverflow
Solution 6 - PhpJustJohnView Answer on Stackoverflow
Solution 7 - PhpJason PalmerView Answer on Stackoverflow
Solution 8 - PhpProdip KirtaniaView Answer on Stackoverflow
Solution 9 - PhpPaulo BoaventuraView Answer on Stackoverflow