I have a form that posts to a processing script which checks for errors in the post. Depending on the p开发者_如何学编程rocessing 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?
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.
}
Put die();
after the header()
function;
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.
精彩评论