Page 1 of 1

Header() help!

Posted: Fri Mar 13, 2009 5:33 am
by SeanTraynor
Hi guys,

I'm having a problem redirecting between my pages. I have a page which I want to continue to execute after i've redirected the user.
I've simulated that page doing work with the sleep command. The redirect only occurs after the sleep has completed.

test1.php

Code: Select all

<?php
 
header("Location: http://whatever.php");
 
sleep(60);
 
?>
whatever.php

Code: Select all

<?php
 
echo("You got here!");
 
?>
Why does PHP wait 60 seconds before sending the header to redirect the page?
I've tried a flush(); after the header but that doesn't work either.

Any ideas?

Re: Header() help!

Posted: Fri Mar 13, 2009 5:59 am
by Mark Baker
Simply setting a redirect header doesn't stop the script executing. It will continue through to its conclusion unless you exit() to terminate the script after sending the redirect header

Re: Header() help!

Posted: Fri Mar 13, 2009 6:04 am
by SeanTraynor
Mark Baker wrote:Simply setting a redirect header doesn't stop the script executing. It will continue through to its conclusion unless you exit() to terminate the script after sending the redirect header
I know that, and that's exactly the behaviour that I want to make use of.

What i'm saying is why does it take 60 seconds for the header() to be sent? even after a flush?

I need a way of forwarding the user while the execution continues behind.

Re: Header() help!

Posted: Fri Mar 13, 2009 6:11 am
by Mark Baker
In that case, you really need to spawn off a separate process to handle the "background" function independently of the called script, then terminate the called script to force the headers to do the redirect

Re: Header() help!

Posted: Fri Mar 13, 2009 6:13 am
by SeanTraynor
There's no way to just force the header to be sent while execution continues?