Kevin Simper
Kevin Simper

Reputation: 1687

Codeigniter header() error

I have run into this problem in my Codeigniter app:

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

I have been checking for whitespaces and I am not sending headers.

The ONLY way this error appears is when I am updating the view and controller files.

My code ran fine until I updated some files, then the error (above) refuses to disappear.

When I clear my cache and log back in again, the error doesn't show.

Does anyone know why?

Upvotes: 0

Views: 3613

Answers (3)

Kevin Simper
Kevin Simper

Reputation: 1687

I have checked for whitespaces, none. I am not using session yet, i am only setting it to session variables in the login script. The ONLY place i use it.

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');
    }

}

In the different views there is only echoing php variables and HTML.

Upvotes: 0

Timur
Timur

Reputation: 6718

May be UTF-8 BOM marker? Try saving training.php without BOM (if exists)

Upvotes: 2

Cyclone
Cyclone

Reputation: 18295

I'm not sure why it would appear and disappear like that, but you're sending output in /application/controllers/training.php on line one, which means that any script run after that cannot modify the header. Essentially, something is invoking CI's session library in a way which is modifying the header, but the header's been sent. It'd be helpful if we could see line one of training.php.

Upvotes: 0

Related Questions