EllisLab text mark
Advanced Search
1 of 2
1
   
Cannot modify header information - headers already sent problem
Posted: 04 March 2008 09:47 PM
Joined: 2008-03-04
3 posts

you can check our site here http://www.cebufreeinfo.com/client/main/4

error:
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/rainier/public_html/cebufreeinfo.com/system/application/controllers/client.php:1)

Filename: libraries/Session.php

Line Number: 295

here is the source code for client.php
(can’t paste all here because of character limit)
client.php

 
Posted: 05 March 2008 01:42 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-23
3194 posts

welcome to CodeIgniter kaging.  That’s a very common error, if you search the forums you’ll find lots of people having that issue, and its always the same solution.  Look for spaces or line breaks before your opening <?php tag.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

 
Posted: 05 March 2008 01:55 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-03-04
3 posts

i already searched everything and removed all spaces for <?php and ?>
i tried to upload my site to other webhosting everything went fine, maybe a webhosting problem?

 
Posted: 06 May 2008 11:14 AM   [ # 3 ]   [ Rating: 0 ]
Joined: 2008-04-11
3 posts

Hi Derek,

I notice your post regarding leading spaces and line breaks before the <?php. 

And I just wanted to ask if the URL Helper redirect() function will cause this same error?

I am suspecting so at the moment, which puts me in a bind. 

My client’s web host won’t allow the buffering turned on in the php.ini.  And I have used the redirect() function a fair bit through my code, and I don’t really want to have to set headers for every redirect. I want to do the redirect as that way the user will have the correct URL in their browser.

Any suggestions…?

How do I avoid the Error with Redirect?  E.g.

A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/rtwell00/public_html/code/application/libraries/Profiler.php:1)
Filename: libraries/Session.php
Line Number: 295

 Signature 

cheers

Pk Byron

“We only ever get angry when others aren’t being who we want them to be!”

 
Posted: 06 May 2008 11:22 AM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-23
3194 posts

Yes, redirect will cause that error.

You don’t need any php_ini stuff, just make sure that nothing is going to the screen first.  In your case, start by turning off the profiler, see if that helps.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

 
Posted: 06 May 2008 11:23 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-25
833 posts

hello,

ensure you do not echo.. print_r any content before you do the redirect. (and check there are no white spaces outside the <?php tags as this will also send a space to the browser)

the redirect requires header information being sent, and if you display any content before the redirect then the header information will have already been sent. I think you also get this problem when setting session data as that requires headers to be sent also.

 
Posted: 06 May 2008 11:26 AM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-04-14
12 posts

check /home/rtwell00/public_html/code/application/libraries/Profiler.php

strip any space and line before <?php

 Signature 

will work for bandwidth

 
Posted: 06 May 2008 12:53 PM   [ # 7 ]   [ Rating: 0 ]
Joined: 2008-04-11
3 posts

Thanks gtech, and thanks for your heads up too ngkong. Have definitely checked that no output is coming out prior to my redirect calls.  And have also check every single file for space before <?php and after ?>, and even went to the extent of removing closing ?> too.

Still this appears to be a fundamental problem with the redirect and not having the php.ini output_Buffering=On . It seems more of a comms/protocol issue.

my only work around is to have all of my functions put in to the one controller and a _remap function implemented - this way I wont have to redirect, all I have to do is just call the functions.  I was thinking about trying to do some chaining controllers, but after reading the posts it appears that this is desperately discouraged (though this is perhaps the perfect situation where it would be appropriate??? what do you think?)... Unless any one else has any ideas…

regards,
PkByron

 Signature 

cheers

Pk Byron

“We only ever get angry when others aren’t being who we want them to be!”

 
Posted: 06 May 2008 01:19 PM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-23
3194 posts

That just doesn’t sound right PkBryon.

What happens if you create a absolutely minimal example

<?php

class Test extends Controller {

    
function __construct()
    
{
        parent
::Controller();
    
}

    
function index()
    
{
                $this
->load->helper('url');
                
redirect('test/foo');
    
}


    
function foo()
    
{
                
echo "redirected";
    
}

}
?> 
 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

 
Posted: 07 May 2008 11:18 AM   [ # 9 ]   [ Rating: 0 ]
Joined: 2008-04-11
3 posts

Hi Derek,

thanks for your interest.  I have found some interesting results (for me at least) from your test script….

1. I copied the code into a file which I saved as Test.php in my controllers directory, as expected.
2. When I tested URL localhost/code/Test.php, it came up with an error.
——-
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at [~]/web/code/application/libraries/Profiler.php:1)

Filename: helpers/url_helper.php

Line Number: 487
——-
(Please Note: I edited the path of the file, but the Profiler.php class in error was a Library class that I wrote.)

...So this all told me that there was a problem with my library class file.  I must have checked the file 10 times, and there was no way there was a leading, or trailing space, with respect to the <?php, and ?> tags respectively.

3. I turned buffering=On in my php.ini file and your Test.php file worked as expected.  Turned output_Buffering=Off and it didn’t.

4. So I went back and looked at everything about that file.  And as I use Textmate, and on a Mac, I looked at the encoding of the file and the line terminations - UTF8 (Recommended) and CRLF (where LF is Recommended).  The file was also designated as a HTML bundle in Textmate - which was probably due to organic movement of code as I developed. 

5. So I copied all the code in the file, and put it into a brand new file, saving it first time as a .php, and making sure the editor had all the php encodings set properly - UTF8 and LF.

6. Bingo! This worked a treat.  (php.ini has output_Buffering=Off, and no redirect issues at all! Yippee).

I haven’t taken any additional time to delve into whether it was the file bundle settings or the line feed character settings, as I need to hit my deadline.  But I hope this (long winded) description can help, anyone on the formus, if another falls into this niche problem I have had.

BTW - appreciate the code snippet, really appreciate it.

regards,

PkByron

 Signature 

cheers

Pk Byron

“We only ever get angry when others aren’t being who we want them to be!”

 
Posted: 07 May 2008 12:25 PM   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-23
3194 posts

Great stuff.  Glad you have it Pk, welcome to CodeIgniter!

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

 
Posted: 10 March 2010 07:22 PM   [ # 11 ]   [ Rating: 0 ]
Joined: 2010-02-19
6 posts

[SOLVED]

[SOLUTION] It’s due to having some text being sent to the browser before all the header items have completed. Yes, exactly as the CI Administrator stated.

[CASE] In my case it was extra space at the bottom of my Helper page, after the last closing ?> tag.

Hope that helps smile

 
Posted: 10 March 2010 07:44 PM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-24
67 posts

Did you really feel the need to bump a two year old thread just to let us know you found the same mistake the original poster had found two years ago? I’m confused…

 
Posted: 04 May 2010 04:30 AM   [ # 13 ]   [ Rating: 0 ]
Joined: 2010-04-13
1 posts

PK Byron I wasted almost 2 hours due to this ‘problem’ and your solution (enconding the file to UTF8) solved my problem! Thanks for sharing this!

troy_mccormick I really felt like I should thank PK Byron for sharing his solution, even when he posted almost 2 years ago, as I have checked my file thousand times for blank spaces and the problem was solved just by changing the encoding!

Cheers!

 
Posted: 04 July 2010 12:59 AM   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-18
9 posts
Derek Allard - 05 March 2008 06:42 AM

welcome to CodeIgniter kaging.  That’s a very common error, if you search the forums you’ll find lots of people having that issue, and its always the same solution.  Look for spaces or line breaks before your opening <?php tag.

That just happend to me, a space before me opening tag was exactly the problem

Thanks!

 Signature 

Gerardo Jaramillo
Web Aficionado

 
Posted: 02 September 2010 04:55 PM   [ # 15 ]   [ Rating: 0 ]
Joined: 2010-05-08
2 posts

i’ve had the same problem with session. i looked for any extra spaces in any file but nothing found!
i just turned on output_buffering in php.ini and yess it workedd!

 
1 of 2
1