Advertisement
Advertisement


Page redirect after certain time PHP


Question

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?

2011/05/25
1
95
5/25/2011 4:12:19 AM

Accepted Answer

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)

2014/06/12
230
6/12/2014 1:51:45 PM

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
2011/05/25

You can try this:

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

Where 10 is in seconds.

2011/05/25

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.

2011/05/25

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!

2017/09/23

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

2011/05/25

Source: https://stackoverflow.com/questions/6119451
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]