I\'m creating a script to validate a form and I was asking myself a question. When I use a header (see example below), do I need to use exit right after? I mean, does using head
Although the answers above sound great, if you're unsure of your code path, this could lead to unexpected results. For example, if you're using a framework that relies on the fact that code execution will run from beginning to end, you may inadvertently interrupt it.
This might be okay from a user perspective as they will still be redirected and will be none the wiser, but consider the following:
You're using a framework (OS or custom) that is expecting to log redirects, or set additional headers (or any number of other items). By calling exit
, you're circumventing that logic and therefore may get unexpected results.
So in short, yes the above methods will work, just a word of caution to know what you're expecting to happen before short circuiting it.