Hello all,

This seems like a helpful little forum, so here goes. I'm getting the Cannot modify header information error. All of the solutions that Google has brought me to tells me to remove the white space around the opening and closing php tags. Well, there is no white space around the tags. I've actually removed all the white space from all of my files. Where can I go next in trying to resolve the error? I won't post any code just yet because I have a ton of code that could be the issue. Thanks in advance for your help!

Recommended Answers

All 11 Replies

It's the sledgehammer approach but the simplest way may be to do an ob_start(); right after your <?PHP statement and an ob_end_clean(); right before the point where you are doing a re-direct (or whatever...).

Thanks for the speedy response, but that didn't seem to do the trick. The only way I've gotten it to not show up is if I edit my php.ini file with output_buffering=on; but that breaks the functionality :(

Try a very simple trick:
Just put

<?echo "blah";

directly at the top of the current PHP source code where you want to modify the header. Then run the code and open the HTML source code in your browser and have a look what stuff is put before "blah". Then you can easily find the module that actually puts text before your header-modification.

I echoed blah at the top of my database file, and for kicks and giggles, at the top of my functions file. when I ran the code in a browser, there were no spaces or breaks before 'blah', but there was the headers error again, this time saying it was in the functions file at line 2, which is where I echoed blah. I'm about to just start writing my code from scratch...

Try commenting out sections of your code. until the error stops. Sometimes there is a PHP "grammatical" error that does not cause a normal error, but crashes php none the less.
It's happened to me on occasion. I think a rouge tick mark will do this in certain instances.

Are you using a code highlighter?

I use phpDesigner 7, and it doesn't bring up any errors like it usually does when I miss a curly brace or the like.

Those highlighters are a great tool , but not 100% foolproof. There is no substitute for setting break points, or running pieces of code at a time.
That, with an eagle eye for synatax, and you're good to go. LOL

This is a giant stab in the dark, but when I run the code locally on wamp, the errors don't show up. When I run the code on my server, which is a lamp config, the errors pop up. Any chance the problem could lie within that?

Yeah, that is a HUGE clue. What versions of PHP, and configuration comparisons are in order.
You might even check the PHP site for known bugs for the particular version, etc.

I wrote a little letter to my hosting company seeing what they have to say. All of the bug reports I could find on the php website basically said "Sorry, this isn't a bug with PHP." The search continues...

I wrote a little letter to my hosting company seeing what they have to say. All of the bug reports I could find on the php website basically said "Sorry, this isn't a bug with PHP." The search continues...

run phpinfo() and see what you have there
Some hosting companies have various limits set in the php.ini.
Notoriously, the max script size.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.