0

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?

murgatroid99
  • 19,007
  • 10
  • 60
  • 95
Kevin Simper
  • 1,669
  • 19
  • 32
  • 2
    What's on line 1 of training.php? – Marc B Sep 13 '11 at 21:38
  • Also, what's up with this question's title? – Cyclone Sep 13 '11 at 21:47
  • @Cyclone Nothing ;-) (edited it) – Bojangles Sep 13 '11 at 21:51
  • 2
    @JamWaffles: Still doesn't make much sense, the user is asking about a header error, not xml – Cyclone Sep 13 '11 at 21:52
  • 3
    Swear to Cthulhu, next person asking a question about "headers already sent by" will get a downvote and a closevote. RTFM dangit. – NullUserException Sep 13 '11 at 21:54
  • @Cyclone And why did I not realise that... Thanks for the heads up. – Bojangles Sep 13 '11 at 21:55
  • that title makes me want to push the downvote button :/ – Karoly Horvath Sep 13 '11 at 21:56
  • @NullUser The OP says he's checked for whitespace and isn't sending headers, so it'll probably be something in Codeigniter somewhere. This is another reason why I don't use frameworks. – Bojangles Sep 13 '11 at 21:56
  • @NullUserException: then maybe you are interested in this: http://meta.stackexchange.com/questions/105838/feature-request-tips-hints-based-on-tags – Karoly Horvath Sep 13 '11 at 21:57
  • @Jam 99% of the time people have issues with established frameworks like CI, it's their fault, not the framework's. – NullUserException Sep 13 '11 at 21:57
  • @JamWaffles: its a very clean framework, easy to patch and extend.. – Karoly Horvath Sep 13 '11 at 21:58
  • Good point Null. And to be fair (yi), I haven't used it so I can't really comment. I just prefer the absolute control I get with using my own code. Personal preference, though. – Bojangles Sep 13 '11 at 21:59
  • @Jam That's the thing though, IMO CI is a very good framework that doesn't take control away from you (like Cake does, for example) while saving you a lot of time on boilerplate code. – NullUserException Sep 13 '11 at 22:17
  • @Kevin Read [this](http://codeigniter.com/user_guide/general/styleguide.html#php_closing_tag) (from the CI style guide); also read the "Whitespace in Files" section. – NullUserException Sep 13 '11 at 23:36
  • Hey guys, i understand what header already sent is a basic error which is easy to fix, but the question is, why does it first appear when i update files through FTP? I have posted the source code further down. – Kevin Simper Sep 14 '11 at 08:09
  • Check if you have 'display_errors' set on and high level of error_reporting, in index.php perhaps or config files. If there is some error in processing in middle stage, that can happen. – jakub.g Sep 14 '11 at 08:23
  • @Null, i dont think you have read my question. The problem was that i have save WITH BOM (lack of knowledge), and that is causing Header Already send. qbk: I actully tried that, setting it from 1 to 4 for all errors, and it did not show any errors. But thank you! – Kevin Simper Sep 14 '11 at 09:42

3 Answers3

2

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

Timur
  • 6,668
  • 1
  • 28
  • 37
  • I am going to try that now, but how what that help? Just asking out of curiosity, because you must think it could be a reason. – Kevin Simper Sep 14 '11 at 08:20
  • I think you solved my problem! I never heard of BOM, but then i search for it, and find out that it can cause header already send! http://stackoverflow.com/questions/2558172/utf-8-bom-signature-in-php-files _"BOM would cause Headers already sent error, so, you can't use BOM in PHP files"_ - Now i have to create all my files again, damm. – Kevin Simper Sep 14 '11 at 09:35
  • This is a common problem... So, have you tried to save your file without BOM? Is this solved your issue? – Timur Sep 14 '11 at 16:12
  • someone should give bounty for this answer. – Syed Abdul Qadeer Jul 22 '13 at 19:47
0

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.

Cyclone
  • 17,939
  • 45
  • 124
  • 193
0

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.

Paweł Tomkiel
  • 1,974
  • 2
  • 21
  • 39
Kevin Simper
  • 1,669
  • 19
  • 32