Ian
Ian

Reputation: 745

Php header redirect

I have a header redirect in place which works however it seems to run through my code twice when ied rather it just redirect and then do the code. It seems to do all the code and then redirect and then do all the code. Ive checked this because ive incremented an integer in a session and it comes up to when it actually gets to its destination even though the code to increment the session is AFTER my header redirect.

why is this.

Upvotes: 0

Views: 327

Answers (2)

Nanne
Nanne

Reputation: 64399

Hard to say without some code, but this is one i've seen a lot: If you call the header, your code does not stop. So the header sents some stuff to the browser, but the code will keep on running.

If the execution should stop after your header, explicitly call die or exit

Upvotes: 4

aorcsik
aorcsik

Reputation: 15552

I recommend putting an exit; after every header redirection. The php code is not terminated when you do the redirect, and this could lead to such behaviour.

Upvotes: 1

Related Questions