Is code after header("Location: …) executed?

前端 未结 5 1329
你的背包
你的背包 2020-12-17 08:35
$_SESSION[\"some_value\"] = 4;
header(\"Location: another-file.php\");
$_SESSION[\"some_value\"] = 5;

what\'s the value of $_SESSION[\"some_v

5条回答
  •  星月不相逢
    2020-12-17 09:18

    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.

提交回复
热议问题