我正在制作一个网站,根据不同的场景进行大量的PHP重定向..就像这样......
header("Location: somesite.com/redirectedpage.php");
Run Code Online (Sandbox Code Playgroud)
出于证券的考虑,我只是想彻底了解重定向的工作原理.我的问题是,在此标头调用之后PHP是否继续执行?
例如......回声是否仍然在这段代码中执行?
function Redirect($URL)
{
header("Location: " . $URL);
}
Redirect("http://somesite.com/redirectedpage.php");
echo("Code still executed");
Run Code Online (Sandbox Code Playgroud)
如果是这样......我会将Redirect功能更改为此...使回显不执行但仍然重定向?
function Redirect($URL)
{
header("Location: " . $URL);
exit(1);
}
Redirect("http://somesite.com/redirectedpage.php");
echo("Code still executed");
Run Code Online (Sandbox Code Playgroud)
出于证券的考虑,我只是想彻底了解重定向的工作原理.
所有header()声明都会修改您的网络服务器(Apache,nginx等)发送到您的浏览器的标头.您已向Location:页面添加了标题,告知浏览器重定向到该页面.PHP脚本中的所有其他内容都将执行,包括您的echo,但您可能无法看到它,因为您将被重定向到新位置.