Possible Duplicate:
php – Should I call exit() after calling Location: header?
I dont know how to title this question but here it goes.
what is the difference between the two code snippets below:
script1 – without exit():
if($var = true){
header('Location: anotherpage.php');
}
script2 – with exit():
if($var = true){
header('Location: anotherpage.php');
exit();
}
from what I understand, header() exits the current page and jumps to another page if the condition is true therefore having exit() after header() is pointless – am I right?
The
header()function just sends a header to the browser along with the rest of your page which tells the browser to redirect. If you don’t want the script to continue running then you should do anexit()in most cases you do want to
exitbecause you do not likely want to output anything to the browser in that case and the extra code will just slow down your redirect.