除了空白之外,还有什么可以触发“已经发送的标题” PHP中的错误 [英] Other than white space what else can trigger "headers already sent" errors in PHP

查看:80
本文介绍了除了空白之外,还有什么可以触发“已经发送的标题” PHP中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个头文件已经发送的问题,但我的问题是,我有一个脚本,我在本地运行(在WinPHP上运行easyPHP)和我的在线服务器(LAMP)。



这对两者都正常工作,并且我没有收到标题错误。

现在我有一个客户端在服务器上运行它,并且他收到了标题错误。



我很确定这个问题是其中的一个文件(我刚发给他一个在?>后面没有断行的文件 - 这可能是一个问题对吧?),但我不知道他为什么会得到这个错误,但我没有 - 即使在?>后面有空格(是的,我的错误报告已打开)

<



快速编辑,阅读下面链接的问题



第一个错误:

 < b>警告< / b>:session_regenerate_id )[< a href ='function.session-regenerate-id'> function.session-regenerate-id< / a>]:Cann ot重新生成会话ID  - 已在 bla bla / includes / lightwork_session.php< / b>中发送的标头在线< b> 33< / b>< br /> 

lightwork_session中的第33行是:我不认为这是问题



pre $ public static function sessionStart(){
//重新生成会话ID以防止会话固定
session_regenerate_id(true); //你好,我是第33行
session_start(); // hello again,我是第34行

}



下一批错误:

 < b>警告< / b>:session_start()[< ; a href ='function.session-start'> function.session-start< / a>]:无法发送会话cookie  - 已在< br /> 

< b>警告< / b>:session_start()[< a href ='function.session-start'> function.session-start< / a>]:无法发送会话缓存限制器 - 已在 bla bla bla / includes / lightwork_session.php中发送(在bla bla / config / config_global.php:167处开始输出的报头)< / b>在线< b> 34< / b>< br />

好吧,config_global.php中的第167行是紧接在?>后面的空格。



我给他发了一个没有空白的文件,但在世界的另一边,我明天会明白这对他是如何解决的。但是我为难他为什么会得到错误,而我却不知道?

解决方案

结束标记后的空格是一个问题,但另一个常见原因是由于PHP警告和通知被转向到他的服务器上更高的报告级别。如果您有任何来自PHP的警告或通知被打印出来,将会导致标题警告。您应该使用以下命令关闭服务器上的通知:

  error_reporting(E_ERROR | E_WARNING | E_PARSE); 

或者只有错误:

 使用error_reporting(E_ERROR); 

我会建议您离开E_WARNING并修复所报告的问题,但至少它会告诉您如果这是问题。


It's a header already sent question but the issue I have is that I have a script which I run locally (easyPHP on Win) and on my live server (LAMP).

This works fine on both and I do not get the header error.

Now I have a client who runs it on his server and he's getting the header error.

I'm pretty sure the issue is one of the files (I've just sent him one with no break lines after "?>" - that can be an issue right?) but I have no idea why he's getting the error but I'm not - even with the whitespace after "?>" (yes, my error reporting is on)

Is there something other than white spaces that can cause this error?

Quick edit, having read the question linked below

First error:

<b>Warning</b>:  session_regenerate_id() [<a href='function.session-regenerate-id'>function.session-regenerate-id</a>]: Cannot regenerate session id - headers already sent in <b>bla bla bla/includes/lightwork_session.php</b> on line <b>33</b><br />

Line 33 in "lightwork_session" is: I don't think this is the issue

public static function sessionStart(){
//regenerate the session id to prevent session fixation
session_regenerate_id(true); //hello, I'm line 33
session_start(); //hello again, I'm line 34 in

}

Next batch of errors:

  <b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at bla bla blaconfig/config_global.php:167) in <b>bla bla bla/includes/lightwork_session.php</b> on line <b>34</b><br />
<br />

<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at bla bla bla/config/config_global.php:167) in <b>bla bla bla/includes/lightwork_session.php</b> on line <b>34</b><br />

Okay line 167 in config_global.php is white space just after "?>"

I've sent him a file without that whitespace but being on the other side of the world I'll find out tomorrow how that works out for him. But I'm stumped as to why he gets the error and I do not?

解决方案

White space after the closing tag is one problem, but another common reason this happens is due to PHP warnings and notices being turned to a higher reporting level on his server. If you have any warnings or notices from PHP that get printed out this will cause the headers warning. You should turn off notices on his server using:

error_reporting(E_ERROR | E_WARNING | E_PARSE);

or to have only errors:

error_reporting(E_ERROR);

I would recommend leaving E_WARNING on and fixing the issues that are reported, but at least it will tell you if that is the problem.

这篇关于除了空白之外,还有什么可以触发“已经发送的标题” PHP中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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