3

在我的应用程序中,我可以确保没有这样的“非故意”空白或其他任何东西。我不在控制器或模型上执行“回显”,但日志文件上总是出现“标头已发送”错误(浏览器中未显示任何内容)。我也没有任何关闭 php 标记。唯一“可疑”的事情是我在模型和控制器上都加载了会话和输入库。

这实际上不是什么大问题,但是如果我使用 CLI 请求,错误会变得很糟糕。

浏览了一会儿,我在堆栈溢出时找到了这个答案: https ://stackoverflow.com/a/13783368/755319 它说我可以在 index.php 的开头添加 ob_start() 用于输出缓冲

<?php
ob_start();
/*
 *---------------------------------------------------------------
 * APPLICATION ENVIRONMENT
 *--------------------------------------------------------------- 

难道是省了做这种事?

编辑:好的,我可能错了,在这里错过了一些东西。有什么程序化的方法可以找出问题所在吗?(一个程序来查找错误的 php 标签、空格或其他东西)?

再次编辑:该错误仅在 CLI 模式下生成。错误如下:

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index: REMOTE_ADDR</p>
<p>Filename: core/Input.php</p>
<p>Line Number: 351</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Cannot modify header information - headers already sent by (output started at /home/gofrendi/public_html/No-CMS/system/core/Exceptions.php:185)</p>
<p>Filename: libraries/Session.php</p>
<p>Line Number: 675</p>
4

2 回答 2

8

Output generated by the first warning will trigger the second warning (i.e: Cannot modify header information ). In theory, if you solve the first warning, the second should auto-fix.

Open system/core/Input.php and at line #351 replace:

$this->ip_address = $_SERVER['REMOTE_ADDR'];

with:

$this->ip_address = $this->server('remote_addr');
于 2013-03-07T13:16:08.930 回答
0

避免输出缓冲的一般原因是它缓冲了输出。这似乎很明显,但是如果您的输出被保存在缓冲区中直到事情结束,那么它直到过程结束才被传送到浏览器,一次。这意味着您的页面似乎不再逐渐加载,但整个事情必须先运行,使其看起来更慢。

所以通常,当除了输出缓冲没有其他方法可以做到这一点时,你可能有一个很好的理由来做同样的事情。

于 2013-03-07T08:32:11.150 回答