Hướng dẫn redirect after timeout php

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?

asked May 25, 2011 at 4:12

3

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]

jp2code

25.8k39 gold badges150 silver badges266 bronze badges

answered May 25, 2011 at 4:19

TeneffTeneff

27.7k9 gold badges64 silver badges96 bronze badges

9

You can use javascript to redirect after some time

setTimeout[function [] {
   window.location.href= '//www.google.com'; // the redirect goes here

},5000]; // 5 seconds

answered May 25, 2011 at 4:15

IbuIbu

41.6k13 gold badges75 silver badges102 bronze badges

2

You can try this:

header['Refresh: 10; URL=//yoursite.com/page.php'];

Where 10 is in seconds.

Wesley Murch

99k36 gold badges189 silver badges224 bronze badges

answered May 25, 2011 at 4:19

royruiroyrui

1,21710 silver badges20 bronze badges

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


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

answered May 25, 2011 at 4:16

JohnJohn

1,5301 gold badge10 silver badges19 bronze badges

0

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 = '//www.google.com'; 
},5000]; // 5 seconds

Jeff Lambert

24k4 gold badges66 silver badges92 bronze badges

answered Jul 3, 2013 at 18:42

JustJohnJustJohn

1,2712 gold badges21 silver badges44 bronze badges

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!

answered Jul 3, 2013 at 16:53

JJJackJJJack

611 silver badge4 bronze badges

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

setRedirectTime[function [] 
{
   window.location.href= '//www.google.com'; // the redirect URL will be here

},10000]; // 10 seconds

answered Jun 13, 2019 at 5:29

Redirect PHP time programming:

 

answered Sep 2, 2020 at 19:56

Paulo BoaventuraPaulo Boaventura

1,2831 gold badge8 silver badges29 bronze badges

Not the answer you're looking for? Browse other questions tagged php redirect or ask your own question.

Chủ Đề