Codeigniter header()错误

时间:2011-09-13 21:34:41

标签: php codeigniter

我在我的Codeigniter应用中遇到了这个问题:

A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /application/controllers/training.php:1)
Filename: libraries/Session.php
Line Number: 671

我一直在检查空格,我没有发送标题。

出现此错误的唯一方法是在更新视图和控制器文件时。

我的代码运行正常,直到我更新了一些文件,然后错误(上面)拒绝消失。

当我清除缓存并重新登录时,错误不会显示。

有谁知道为什么?

3 个答案:

答案 0 :(得分:2)

可能是UTF-8 BOM标记?尝试保存training.php而不使用BOM(如果存在)

答案 1 :(得分:0)

我不确定为什么它会像那样出现和消失,但是你在第一行的/application/controllers/training.php发送输出,这意味着之后运行的任何脚本都无法修改标题。本质上,某些东西正在以修改标题的方式调用CI的会话库,但标题已被发送。如果我们能看到training.php的第一行,那将会很有帮助。

答案 2 :(得分:0)

我检查过空格,没有。我还没有使用会话,我只在登录脚本中将其设置为会话变量。我唯一使用的地方。

<强> training.php

<?php

class Training extends CI_Controller
{

    public function index()
    {
        $data['heading'] = 'Træning';
        $data['smallheading'] = 'Registre dine træningsture og hold styr på dem.';
        $this->load->view('header_view', $data);
        $this->load->view('training_view');
        $this->load->view('footer_view');
    }

}

在不同的视图中,只有回显php变量和HTML。