Welcome Guest, Not a member yet? Register   Sign In
Cannot modify header information - headers already sent
#1

Hi! I'm using CodeIgniter for quite awhile now..and I'm currently facing an error



Code:
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

Backtrace:

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) {
     $this->session->sess_destroy();
     redirect(site_url('login'));
}
  

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
Reply
#2

(This post was last modified: 11-27-2017, 10:39 PM by dunkindonato.)

UPDATE:

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
Reply
#3

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB