Warning: Cannot modify header information – headers already sent.
Warning: Cannot modify header information – headers already sent by (output started at /home/myaccount/public_html/globals.php:42) in /home/myaccount/public_html/includes/mambo.php on line 302
When you start coding your PHP in your early days most of the coders would have come a cross above warning. Experience PHP coders know how to come out of this warning.
What does give you this error warning? When you develop your PHP, XHTML, CSS locally you won’t encounter this problem. It works well, but problems occur at the moment you start hosting your web application. You might have got it even when you do redirects using the below statement.
header(“Location: login.php”);
When you use the above statement you may not always get the waring message. It comes if you have a PHP script on the top of the page. Due to various reasons PHP coders need to include scripts on the top of the page. In my case I had to start the session to read authentication information so I included the below statement.
It was working very well with my local IIS server. Moment I hosted my pages things started to fall apart. So I started digging into google. The common solution which I found was,
The “headers already sent” error is usually caused by having white space before or after the opening and closing PHP tags ().
try placing this at the top of your page:
ob_start(); ?>
then at the bottom of the page place this line of code:
ob_flush(); ?>
But none of the above fixes was able to solve my issue. After doing all of these, if you still encounter this problem you must open you php page on your editor check with what format you are saving it. If you are saving it using UTF-8 better change it to ANSI and host it. All above errors will dissapear.
For the redirects you may need to alter your code a bit, like below,
print “”;
16 Comments
Join the discussion and tell us your opinion.
Finally, an issue that I am passionate about. I have looked for information of this caliber for the last several hours. Your site is greatly appreciated.
@veterinary technician My pleasure if you could have achieved something out of this article. The very same error took me more than day to fix when i was beginning PHP. So thought of sharing the trick.
This is the best email in a browser that I’ve read in a while.
@polar f4 thx
Thanks guys
I happened to stumble across this website searching for something different, glad I stumbled into it though. Very interesting.
You know what… thank you for your post, I don’t concur with you exactly but I agree with it on the most part and I certainly applaud your efforts in trying to put it so succinctly.
@T Shirt Template as i told before this error took me for a ride too. so thought of sharing.
Sounds like a great product. It would probably be a great gift for grandma at Christmas time
Great post, thanks for being humble and sharing. Didn’t know about the shared web host potential.. Good to know owning over a thousand sites..
Cool article. No surprises that Google was number 1…
I found your blog on google and read a few of your other posts. I just added you to my Google News Reader. Keep up the good work Look forward to reading more from you in the future.
Edit: sorry je me suis trompe de site 😉
Et vive la simulation de seotons !!
Quoi, une simulation de seotons ??
Oui oui !
Would you be concerned about exchanging hyperlinks?
WONDERFUL Post.thanks for share..more wait ..
There may be noticeably a bundle to learn about this. I assume you made sure good points in options also.