我应该在调用Location:标头后调用exit()吗? [英] php - Should I call exit() after calling Location: header?

查看:84
本文介绍了我应该在调用Location:标头后调用exit()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用重定向函数头后,是否应该调用exit?

After calling the redirect function header, should I call exit or not?

<?php // fileA
$urlFailToGoTo = '/formerror.php';

if (sth)
{
   header(sprintf("Location: %s", $urlFailToGoTo));
   exit(); //should I call exit() here? or return?
}

?>

谢谢

推荐答案

您绝对应该.否则脚本执行不会终止.单独设置另一个标头不足以重定向.

You definitely should. Otherwise the script execution is not terminated. Setting another header alone is not enough to redirect.

这篇关于我应该在调用Location:标头后调用exit()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆