Cannot modify header information - headers already sent problem |
[eluser]kaging[/eluser]
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
[eluser]Derek Allard[/eluser]
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.
[eluser]kaging[/eluser]
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?
[eluser]PK Byron[/eluser]
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
[eluser]Derek Allard[/eluser]
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.
[eluser]gtech[/eluser]
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.
[eluser]ngkong[/eluser]
check /home/rtwell00/public_html/code/application/libraries/Profiler.php strip any space and line before <?php
[eluser]PK Byron[/eluser]
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
[eluser]Derek Allard[/eluser]
That just doesn't sound right PkBryon. What happens if you create a absolutely minimal example Code: <?php
[eluser]PK Byron[/eluser]
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 |
Welcome Guest, Not a member yet? Register Sign In |