Welcome Guest, Not a member yet? Register   Sign In
'Cannot modify header information' strikes again
#1

[eluser]Unknown[/eluser]
Yes, I've used the search function and read the resulting topics. Yes, I know i cannot send any output before manipulating headers. I don't. It's triple checked.

Still, can't get sessions to work.

This is the code i run:

<?php
class Ajax extends Controller
{
function index()
{
$this->load->library('session');
}
}

Nothing fancy. The closing ?> doesn't matter, it doesn't work with nor without it.

"A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\system\application\controllers\ajax.php:1)

Filename: libraries/Session.php

Line Number: 662"

Line 662 of session.php indeed modifies header information but because of some mysterious output in line 1 of my controller, cannot do that. So, what do I do?

First, i rewrote the controller in a new file, no copy-paste, to make sure the first character is a php opener. Of course, it was too simple to work and it didn't. Then, I decided to check if there are those whitespaces in line 1 that I cannot see added by a editor (I was using Notepad to make sure there aren't, but who the hell knows). I copied the entire controller code into a new file and then remove everything but the first line - I didn't want to touch it since it was the one causing the problem according to CI. Then, in line 2 i did some header manipulation:

<?php
header("Cache-Control: no-cache, must-revalidate");

Saved to new php file and run directly, outside CI.

My idea was: if there is a whitespace in line 1, it got copied so the code won't run. Well, it did. No problem at all.

But maybe the white space didn't get copied? It'd be great! No more header problems! So i changed the code (without touching the line 1) back to my controller code and run it through CI.

FAIL.

Cannot modify... line 1...

CI is out of the box, no changes made to any core files.

Changing output_buffering in php.ini doesn't help.

Please help.
#2

[eluser]Rick Jolly[/eluser]
Some editors add "byte order marks" when saving in UTF-8. I had that problem with Notepad++. I had to save using UTF-8 without BOM (byte order marks).
#3

[eluser]Thorpe Obazee[/eluser]
There's an option in Notepad++ and some editors wherein you can save w/o BOM. I've had this problem with notepad and Pspad.
#4

[eluser]Unknown[/eluser]
Thank you guys sooo much, that was exactly the thing.
#5

[eluser]Mellkior[/eluser]
I use after <?php

<?php
ob_start();




Theme © iAndrew 2016 - Forum software by © MyBB