Jump to content

Sleep func problem


ylkien

Recommended Posts

Hi guys,

I am trying to create a simple script to display some messages, wait, then forwarding it to another page. The problem I have is that it won't display anything if I use the function "sleep". This means, it will straightway goto the redirected page w/o displaying any message...

It will display the message if I use "ob_flush" & "flush", but when trying to redirect it, the error "...headers already sent by..." comes out.

Below is a snipper of the code :

[code]function Transfer_Back( $Sleep_Time )
{

        echo "Hello";
ob_flush();
flush();

Sleep( $Sleep_Time );

Header("Location:http://localhost");
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/29644-sleep-func-problem/
Share on other sites

If you want to output stuff before redirecting, you could use the 'refresh' meta tag in the <head> section of your html

[code]
<meta http-equiv="Refresh" content="3;URL=http://localhost">
[/code]

will redirect the browser to 'http://localhost' after 3 seconds.

Hope that helps!  BTW, using meta refresh won't go down well with some accessibility validators, as it's a bunch of no fun for speech screen readers.
Link to comment
https://forums.phpfreaks.com/topic/29644-sleep-func-problem/#findComment-136072
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.