我想我们大多数人都知道 PHP 中臭名昭著的“ header 已发送”错误。我可以检查一下是否已经发送了 header 吗?
在全力以赴尝试设置一些 SESSION 数据或类似数据之前,这样做真的很方便。
谢谢!
最佳答案
PHP有一个函数headers_sent()
它允许您在采取任何操作之前检查 header 是否已发送。以下是在代码中使用该函数的方法:
if(headers_sent())
{ //if headers already sent out print some message.
echo "Please go to yahoo.com";
}
else{
//send the user automatically to test.php
header('Location: http://yahoo.com');
exit;
}
关于php - 如何检查 header 是否已在 PHP 中发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2820639/