$_SESSION["some_value"] = 4;
header("Location: another-file.php");
$_SESSION["some_value"] = 5;
what's the value of $_SESSION["some_value"]
?
$_SESSION["some_value"] = 4;
header("Location: another-file.php");
$_SESSION["some_value"] = 5;
what's the value of $_SESSION["some_value"]
?
The value is 5.
You can output a lot more headers than just Location
headers with header
, most of which you don't want to stop your code execution. If you want to stop code execution, you need to call exit
explicitly.
The header
command doesn't interrupt the flow of your code. Even if that is encountered, your page is still downloaded by the browser, even if it isn't show. Consider 404 pages, which (despite being errors) are still processed by the browser (though they are rendered while redirects are not).
Once you issue the header, you've started a race between your code and the webserver/browser. Generally, as soon as the browser receives the redirect, it'll close the connection that ran the script and start connecting to the new redirect URL. When the connection's closed, the web server will generally try to kill the script.
You might get lucky and be able to finish off anything else you wanted to do, or your might be unlucky and the script won't even be able to reach the next line after the header()
call.
There is the ignore_user_abort()
function, which should let your script continue regardless of the connection's status, though.