我正在創建一個腳本來驗證表單,我問自己一個問題。當我使用標題(請參閱下面的示例)時,是否需要使用退出權限?我的意思是,使用頭也意味着它默認退出,因此我不需要使用命令退出?我是否需要在標題後使用exit(「Location:http:// localhost/...」);?
// cancel button clicked
if (isset($_POST['cancel'])) {
header("Location: http://localhost/admin/tracks.php");
exit;
}
echo '<p>$name</p>'
我認爲你不需要。發送標題時,您將被重定向,腳本將停止執行。 – EmCo 2011-04-03 05:51:30
@EmCo不完全正確。看我的答案中的例子。 – AgentConundrum 2011-04-03 06:03:51
可能重複[爲什麼我必須在PHP中通過頭('Location ..')重定向後調用'exit'?](http://stackoverflow.com/questions/2747791/why-i-have-to-call-exit-after-redirection-through-through-headerlocation-in-php) – kapa 2012-04-30 09:30:43