tags:

views:

79

answers:

3

I have a form that posts to a processing script which checks for errors in the post. Depending on the processing it header redirects to another location. This appeared to work but I have just noticed that is still executing stuff after the header.

What is going on?

+10  A: 

We will need some code, to see exactly what is going on...

But most likely you sure not using an exit(); or die(); after your header("Location: ...");

e.g.

//check your post

if($errors)
{
    header("Location: errors.php"); // bug fixed =D
    exit();

    // this will still be executed if the exit was not there.
}
Lizard
More explanation I've written here: http://thephpcode.blogspot.com/2009/01/why-exit-after-header-redirect.html
thephpdeveloper
+3  A: 

Put die(); after the header() function;

Brandon
or exit;[...........]
dusoft
A: 

This is correct behaviour - calling header() won't halt the script immediately. For most other headers (Content-type, ETag, Expires, etc.) you don't want it to halt, as those headers relate to the content that's about to follow; in that regard, Location: is slightly unusual.

SimonJ