Header() help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SeanTraynor
Forum Newbie
Posts: 3
Joined: Fri Mar 13, 2009 4:59 am

Header() help!

Post 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?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Header() help!

Post 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
SeanTraynor
Forum Newbie
Posts: 3
Joined: Fri Mar 13, 2009 4:59 am

Re: Header() help!

Post 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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Header() help!

Post 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
SeanTraynor
Forum Newbie
Posts: 3
Joined: Fri Mar 13, 2009 4:59 am

Re: Header() help!

Post by SeanTraynor »

There's no way to just force the header to be sent while execution continues?
Post Reply