Jump to content

header location


LittleJoe

Recommended Posts

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 by LittleJoe
Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...