header 函数 运行 在 PHP 中排序
header function running order in PHP
<?php
header("Location:http://www.example.com");
header("Location:http://example.net");
?>
当我 运行 这段代码时,它被重定向到 example.net
为什么它被重定向到 example.net 而 example.com 出现在 example.net 之前?
那是因为您的第二个 header
替换了第一个,因为您没有使用 header
的可选 replace
参数。来自 manual:
replace
The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same
type. By default it will replace, but if you pass in FALSE as the
second argument you can force multiple headers of the same type
<?php
header("Location:http://www.example.com");
header("Location:http://example.net");
?>
当我 运行 这段代码时,它被重定向到 example.net
为什么它被重定向到 example.net 而 example.com 出现在 example.net 之前?
那是因为您的第二个 header
替换了第一个,因为您没有使用 header
的可选 replace
参数。来自 manual:
replace
The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same type. By default it will replace, but if you pass in FALSE as the second argument you can force multiple headers of the same type