Php Post Redirect Get pattern,exit()函数porpuse

Php Post Redirect Get pattern,exit()函数porpuse,php,redirect,exit,Php,Redirect,Exit,我试图理解Post Redirect Get的模式,在几个例子中,人们在重定向后放置了一个exit(),如下所示: if ($_POST) { // Execute code (such as database updates) here. // Redirect to this page. header("Location: " . $_SERVER['REQUEST_URI']); exit(); } 我的问题是关于exit()函数的。有什么关系?对我来说,它从未

我试图理解Post Redirect Get的模式,在几个例子中,人们在重定向后放置了一个
exit()
,如下所示:

if ($_POST) {
   // Execute code (such as database updates) here.

   // Redirect to this page.
   header("Location: " . $_SERVER['REQUEST_URI']);
   exit();
}

我的问题是关于
exit()
函数的。有什么关系?对我来说,它从未被读取过,因为页面在“php解释器”到达之前被重定向。

正如你所说,没有被调用

但在你问问题之前,你可以做一个小测试来检查它是否被调用

if ($_POST) {
   // Execute code (such as database updates) here.

   // Redirect to this page.
   header("Location: " . $_SERVER['REQUEST_URI']);
   $fp = fopen("log.txt", "a");
   fwrite($fp, "called");
   fclose($fp);
   exit();
}

因此,如果您看到一个名为log.txt的文件,那是因为调用了exit函数,如果没有文件,则表示未调用exit。

我看不出downvote的原因。正如我所说,exit()函数没有被调用,但是我在搜索一个未知的事实,正如我所说的,我做到了。我以为我忘了什么把戏。