LittleJoe Posted December 16, 2012 Share Posted December 16, 2012 (edited) I have a pretty long script with two header functions which make use of the HTTP location thing. So basically, if a certain criteria is met then the first one is fired otherwise the script is supposed to continue until it gets to the second one. However, the script always seems to jump over the first one and not stop there but to continue until it reaches the second one. Example: if ($somethingIsTrue){ header("Location: first.php");} // a whole lot of code header("Location: second.php"); The only way to get it to stop at the first one is to do this: if ($somethingIsTrue){ header("Location: first.php"); exit;} // a whole lot of code header("Location: second.php"); Otherwise it just runs over the first one. Is this normal? Is there something that I'm missing? Edited December 16, 2012 by LittleJoe Link to comment Share on other sites More sharing options...
boen_robot Posted December 16, 2012 Share Posted December 16, 2012 Yes. It's normal.What you're missing is that PHP collects all headers, and only sends all of them once output starts, or when the script is finished (whichever comes first). By doing "exit;", you're forcing the end of the script, and thus all headers are sent. Link to comment Share on other sites More sharing options...
LittleJoe Posted December 17, 2012 Author Share Posted December 17, 2012 Yes. It's normal. What you're missing is that PHP collects all headers, and only sends all of them once output starts, or when the script is finished (whichever comes first). By doing "exit;", you're forcing the end of the script, and thus all headers are sent. That actually makes sense. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now