In a PHP program can header() redirects be counted on to end the program flow, or is there value in, for example, following them with a die() to be safe? Is it possible for the user to exploit the script by somehow forgoing the redirects? This question is crucial in a case where the user is redirected for not having sufficient access permissions and the code following is intended only for those who were not redirected.
Share
No, header do not end the program execution. You must end it yourself with exit or die. You can try this yourself with something like this:
Check the content of
/tmp/testand you’ll find that it is2.I’ve also tried this script:
together with telnet to send a manual HTTP request, with this result:
As you see, everything which is echoed after the Location header is still sent to the browser. In fact, PHP cannot know after a
headercall if you are going to send it more headers, or if the things you echo out are of importance.