CodeIgniter Forums

Full Version: Cannot modify header information - headers already sent
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi! I'm using CodeIgniter for quite awhile now..and I'm currently facing an error

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /project/system/core/Exceptions.php:271)

Filename: helpers/url_helper.php

Line Number: 564


File: /project/application/core/MY_Controller.php
Line: 75
Function: redirect

File: /project/application/controllers/User.php
Line: 116
Function: user_view

This is Line 75 of My_Controller

PHP Code:
if( ! $this->session->email || $this->session->email == NULL || $this->session->isLoggedIn !== TRUE) {

just incase this is needed, I used echo in my User controller because this is where I get some ajax request.

Thank you very much Smile

I just found out that this one might be the one causing problem.
PHP Code:
$data['pending_count']   = ($pending->count $pending->pages);
$data['paid_count'     = ($paid->count $paid->pages);
$data['cancelled_count'] = ($cancelled->count $cancelled->pages); 

I cannot use redirect(site_url('login')); below this code. But if I put redirect before $data[] it works just fine.

Is there any way I can solve my error? Thank you! Smile
You get the headers already sent error because you have written to the output already.

Which is most Lilly what the $data is doing. So yes you would need to redirect before
you write the $data to the view.