Redirecting a page after a certain time PHP

There is some PHP function to redirect after a while. I saw him somewhere, but I don’t remember. This is similar to gmail redirect after login. Please can anyone remind me?

+86
redirect php
May 25 '11 at 4:12
source share
9 answers
header( "refresh:5;url=wherever.php" ); 

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




Remember that header () must be called before sending any actual output, either using regular HTML tags, empty lines in a file, or from PHP. A very common mistake for reading code with an inclusion or request, functions or another function for accessing files, as well as spaces or empty lines that are displayed before calling header (). The same problem exists when using a single PHP / HTML file. ( php.net source)

+210
May 25 '11 at 4:19
source share

You can use javascript to redirect after a while

 setTimeout(function () { window.location.href= 'http://www.google.com'; // the redirect goes here },5000); // 5 seconds 
+25
May 25 '11 at 4:15
source share

You can try the following:

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

Where is 10 seconds.

+16
May 25 '11 at 4:19
source share

you would like to use php to write a meta tag.

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

Not recommended, but possible. 5 in this example is the number of seconds before it is updated.

+11
May 25 '11 at 4:16
source share
 header( "refresh:5;url=wherever.php" ); 

indeed you can use this code, as teneff said, but you don’t have to put the header in front of any output sent (this will lead to the conclusion “it is not possible to move the header ....: 3 errors”).

To solve this problem, use the php function ob_start(); before the output of any html.

To complete ob, just put ob_end_flush(); after you have no html output.

Hurrah!

+2
Jul 03 '13 at 16:53
source share

Updating PHP after 5 seconds did not work for me when I opened the Save As dialog to save the file: (header ('Content-type: text / plain'); header ("Content-Disposition: attachment; filename = $ filename>") ;)

After the "Save As" button was pressed and the file was saved, the time update stopped on the calling page.

However, thanks a lot, the ibu javascript solution just kept ticking and refreshing my web page, and this is what I need for my specific application. So thanks ibu for posting javascript to solve php problem.

You can use javascript to redirect after a while

 setTimeout(function () { window.location.href = 'http://www.google.com'; },5000); // 5 seconds 
+2
Jul 03 '13 at 18:42
source share

If you are redirected using PHP, you will simply use the sleep () command to sleep a few seconds before the redirection.

But I think you mean the meta refresh tag:

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

+1
May 25 '11 at 4:16
source share

My suggestion is to use the sleep() function.

 <?php sleep(5); header('location'.URL); ?> 
0
Oct 08 '15 at 1:06 on
source share

You can use this JavaScript code to redirect after a certain time. Hope this works.

 setRedirectTime(function () { window.location.href= 'https://www.google.com'; // the redirect URL will be here },10000); // 10 seconds 
0
Jun 13 '19 at 5:29
source share



All Articles