【问题标题】:How to diagnose error : Unable to add cookies, header already sent如何诊断错误:无法添加 cookie,标头已发送
【发布时间】:2012-02-02 07:14:30
【问题描述】:

错误:无法添加 cookie,标头已发送。

我想知道是否有任何方法可以有效地诊断上述错误。
我了解此错误的原因 - 在将其他内容(例如标头、html 等)发送到浏览器之后发送 cookie 时。

有数百个文件和数千行代码。如果有人知道一种方法(即使是第 3 方,也没关系),它将帮助我找到在 cookie 之前将哪些内容发送到浏览器,这样我就可以轻松地操作这部分代码。我无法找到导致此错误的实际位置或代码补丁。

一般情况下,许多 vBulletin 用户都会遇到这种情况,vB 工作人员会告诉您禁用模组/插件等。但我想知道找到问题位置的任何有效方法。 <?php等等等等都没有问题。

【问题讨论】:

  • 首先使用 tcpdump 捕获生成的页面并查看第一个字符。很有可能,开头有杂散的空白,因此您可能想要搜索不以 结尾的脚本

标签: php cookies header http-headers


【解决方案1】:

请参阅 cookie 设置点的header_sent() 函数。 php function header_sent()可以帮到你。

bool headers_sent ([ string &$file [, int &$line ]] )

If the optional file and line parameters are set, headers_sent() will put the PHP source file name and line number where output started in the file and line variables.

【讨论】:

  • +1。它返回 true,我用 headers_list() 函数打印了标题。已发送的标头是:数组( [0] => X-Powered-By: PHP/5.2.17 [1] => Content-type: text/html )。有谁知道 vBulletin 的哪个部分正在发送此标头?或者如何追踪位置?
  • 已编辑答案。您可以使用相同的功能来做到这一点
猜你喜欢
  • 2013-05-15
  • 2014-06-09
  • 1970-01-01
  • 1970-01-01
  • 2013-06-07
  • 1970-01-01
  • 2013-06-12
  • 2016-06-17
  • 1970-01-01
相关资源
最近更新 更多