Cannot modify header information – headers already sent

Contributor Icon Contributed by qmchenry  
Tag Icon Tagged: 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.

 

149 Comments -


  1. Tim Glenn said on October 22, 2008

    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);

  2. elz said on October 22, 2008

    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.

  3. elz said on October 22, 2008

    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

  4. Quinn McHenry said on October 23, 2008

    That’s great — thanks for sharing! I haven’t run into this before, but now that you point it out, it makes sense.

  5. Andrei said on November 1, 2008

    Thanks a lot for this post!
    #3 solved my problem! :)

  6. Adrian Angelov said on November 6, 2008

    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.

  7. Affordable Web Design said on November 8, 2008

    Good advice thanks for the post

  8. P M said on November 10, 2008

    Very informative article. It was the blank line that was my problem. This article clearly explains subtle issues.

    Thanks

  9. Packing Machines said on November 13, 2008

    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

  10. charlitos said on December 12, 2008

    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 :(

  11. Jon said on December 18, 2008

    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!

  12. Chris said on January 18, 2009

    Thanks!

  13. Fr said on February 3, 2009

    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.

  14. Klaus said on February 3, 2009

    Thanks, helped me a lot.
    Amazing what some additional unnoticed whitespace can cause havoc
    sometimes.

  15. Dan said on February 6, 2009

    It did work! Colour me amazed! Ta!

  16. Sachin said on February 19, 2009

    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..

  17. Quinn McHenry said on February 19, 2009

    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!

  18. dave said on February 25, 2009

    wwwwwwwwwwwwwoooooow thanks sir problem solved,, stupid white space

  19. dominic said on February 26, 2009

    This helped me to some my problem. Where i was trying to generate a xml file using php.

    Thanks

  20. Fr said on February 26, 2009

    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.

  21. RORO said on March 16, 2009

    This did it! THANKS SO MUCH!! Nothing else worked and I tried it all!

  22. MetalGarurumon said on March 19, 2009

    Thanks! It works now :)))

  23. manuel said on April 23, 2009

    how can modify display_error in php script ?

  24. Lito said on April 28, 2009

    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

  25. IMQ said on April 28, 2009

    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.

  26. the Jim Gaudet said on May 8, 2009

    U DA MAN… Removing DOM fixed it…

  27. Anonymous said on May 14, 2009

    thnks………
    i have been working on the same for the past 5 days……….. the error i had was a space before PHP tag..

  28. Andy said on May 17, 2009

    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!

  29. mark said on May 27, 2009

    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.

  30. Anonymous said on June 4, 2009

    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

  31. neoniflor said on June 6, 2009

    That was fun….. whitespace really where a problem… thanks

  32. Mithus said on June 11, 2009

    That really great….thanx…..sooo mch….

  33. Jamie said on June 11, 2009

    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!

  34. Leandro said on June 19, 2009

    I had an include with two blank lines after the ?> in that include… I deleted those blank lines and It works perfectly!

    Thanks!

  35. dinesh said on June 20, 2009

    Make sure there is no white space outside of the php start and end tags

    This is really a culprit.
    Thanks for help.

  36. Emmanuel Afonrinwo said on June 28, 2009

    Thanks a lot, after reading and carefully looking through the codes paying attention to your advice theproblem was resolved.

  37. Charlies said on July 2, 2009

    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

  38. aneesniittech said on July 22, 2009

    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

  39. Alla said on August 19, 2009

    I love you.
    I had white spaces in my include files.
    Hours upon hours of frustration and headaches.
    Thank you.

  40. Anonymous said on August 21, 2009

    Gre8!! i’ve been tryin to solve this prob from the early morning.everything works fine now:D:D:D 1000x

  41. RS said on September 6, 2009

    that does NOT always work… (white space solution that is)…
    this error can be for different reasons….

  42. AffiliIt Reviews said on September 12, 2009

    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 :)

  43. anant tiwari said on September 15, 2009

    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

  44. anant tiwari said on September 15, 2009

    Ah….!
    I got the problem,.. anyway thanks for all

  45. anant tiwari said on September 15, 2009

    Ah….!
    I got the problem,.. anyway thanks for all

  46. Ivan said on September 23, 2009

    Thank You!!!! :)

  47. amir said on October 11, 2009

    I owe you a kiss !!! ;)
    Thanks for the post

  48. Anonymous said on October 23, 2009

    This article helped me bunches. Thanks.

  49. Paul said on November 2, 2009

    Thanks, I just had this problem, and your post solved it! I am a php newb, I almost had to reinstall my whole site.

  50. Anonymous said on November 6, 2009

    call ob_start(); function at the start of function,It will turn output buffering on, n no output will sent from script.

  51. katy said on November 19, 2009

    Jon I want to kiss your feet. I changed my file to ANSI and not UTF-8 and it works! Brilliant. I love you!

  52. Kjarri said on December 1, 2009

    Grepping for a tag solved it for me;

    kjarri@hel:~/public_html/old_os$ grep -R “” *
    includes/header.php:

  53. Alex said on December 2, 2009

    in php.ini file:

    >output_buffering = 4096

    It’s works!

    >output_buffering = On

    It’s bad!

  54. Anonymous said on December 5, 2009

    I do this mistake (leaving a whitespace commonly) while I just beginner…

  55. Anonymous said on December 7, 2009

    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!!!

  56. Vijendra Mishra said on December 10, 2009

    Nice Help Thanks it’s really great

  57. Anonymous said on December 15, 2009

    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

  58. Mohsin Shah said on December 16, 2009

    Thanks, tip number 3 saved my day :)

  59. netsuke said on December 25, 2009

    Thanks. Erased ?> and works like a charm.

  60. webPavulon said on January 14, 2010

    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.

  61. Anonymous said on January 19, 2010

    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.

  62. Anonymous said on January 26, 2010

    yess..
    thx you,,
    its solved now

  63. brandon said on January 28, 2010

    this solved my problem THANK YOU!!!

  64. Anonymous said on February 3, 2010

    thx bro

  65. Nawedita said on February 5, 2010

    Thanks…..i solve my problem by this site.
    Good Job

  66. Anonymous said on February 7, 2010

    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!

  67. Rajesh said on March 12, 2010

    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.

  68. Anonymous said on March 13, 2010

    Very good and simple. Found header() and found my problem. Thanks

  69. Higor Câmara said on March 24, 2010

    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…….

    -

  70. Anonymous said on April 24, 2010

    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ü.

  71. Nova said on May 6, 2010

    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

  72. Mike Bobbitt said on June 8, 2010

    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.

  73. ML said on June 21, 2010

    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

  74. Sherbertfiddler said on July 2, 2010

    Beware of include files! They could have extra lines after your closing php tag. This was the culprit in my case.

  75. Mia said on July 4, 2010

    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 :D )
    M

  76. Anonymous said on July 4, 2010

    Glad we could help!

  77. Tom Eagles said on July 12, 2010

    brilliant thx, :)

  78. chitvendra said on July 19, 2010

  79. Skssumit744 said on July 20, 2010

    $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”; } } }?>

  80. Skssumit744 said on July 20, 2010

    i have recive this error..

  81. Skssumit744 said on July 20, 2010

    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

  82. Reza said on July 24, 2010

    it works good.
    thanks a lot

  83. Sunny aggarwal said on July 29, 2010

    u ppl r genious…..i gt many 4m ur lil description…thx…

  84. Surendra said on August 1, 2010

    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.

  85. Captain Marvel said on August 11, 2010

    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!

  86. Jayvee_chua said on August 18, 2010

    thanks so much for this article!!! didn’t realize that the blank line above the header() is the one causing the error.

  87. NoahY said on August 29, 2010

    Yes, that did it :) change encoding to “None” and the problem goes away.

  88. Kieron said on August 31, 2010

    Woops, heres my error

    Warning: Cannot modify header information – headers already sent in C:xampphtdocsoneillglasscmsnews_edit.php on line 55..

  89. Kieron Keenan said on September 1, 2010

    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.

  90. Tiyo Kamtiyono said on September 10, 2010

    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, :)

  91. Wpko said on September 13, 2010

    qmchenry : Thanks you too much, the two extra lines after ?> php closing tag, give us a lot problem. your article help us.

  92. Rajnikant12345 said on October 6, 2010

    Thanks buddy, it worked and I learned a new thing .

  93. Anne Shiever said on October 7, 2010

    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

  94. nafri said on October 9, 2010

    very recommended solution, work for me, thanks.

  95. cgal said on October 20, 2010

    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!

  96. Jack said on October 24, 2010

    Great tip qmchenry! That fixed the problem for me. I never knew the closing tag wasn’t necessary.

  97. GsfurfA said on November 3, 2010

    good for you

  98. Guth said on November 3, 2010

    than give me one

  99. Uth said on November 3, 2010

    my feet aren’t clean but you can

  100. GUTH2 said on November 3, 2010

    YOUR WELCOME

  101. Web Site Helper said on November 5, 2010

    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.

  102. Robdavidsalmon said on November 7, 2010

    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!

  103. Anonymous said on November 7, 2010

    Thanks for the kind words. We have a pretty neat little community here. :)

  104. Derek said on November 11, 2010

    You’re a genius! Thanks so much.

  105. technology guru said on December 2, 2010

    hiya
    i got an easy solution for it… u check that are u calling header() function wrong

  106. Torsten Dreier said on December 10, 2010

    Worked for me. Thanks

  107. Rahmadhany T said on December 14, 2010

    one more,
    delete blank lines on your script!

  108. Rahmadhany T said on December 14, 2010

    i mean point no.3.

  109. Nniesen said on January 3, 2011

    Add this to the top of your code:

    ob_start();

  110. Chenzhou_liufaming said on January 5, 2011

    thanks

  111. rich said on January 17, 2011

    I’m having the exact same problem. No header() redirect code and the line involves my setcookie() function

  112. rich said on January 17, 2011

    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.

  113. rich said on January 17, 2011

    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.

  114. rich said on January 17, 2011

    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*

  115. Sendilrr said on February 1, 2011

    I have corrected this error. please include ob_start(); in your connection file.

  116. Sendilrr said on February 1, 2011

    please include in your top of the file and please include in your bottom file;

  117. mrm said on February 2, 2011

    I’m having the same problem here is my code:

  118. Neo said on February 14, 2011

    thanks

  119. Muhammad Farooqi said on February 20, 2011

    OOH.. myGod.. excellent man…

  120. Darisx said on March 4, 2011

    Thanks, I have been solved header() problem.

  121. Ddbhp said on March 4, 2011

    This solved my issue!! Obviously I need to study this php.ini and see what other magic can be controlled here ;)

    THANKS!!!

  122. Cameron St.Michael said on March 11, 2011

    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!

  123. Jclark_4321 said on March 13, 2011

    Wow. I honestly cannot thank you enough for this. I somehow got a space before my opening

  124. Todljd said on March 22, 2011

    not too bad

  125. Jamescb0 said on March 26, 2011

    Thanks for that… removed the “HTML DOCTYPE” statement at the very top and all working now.. cheers

  126. Dan said on March 26, 2011

    Removing BOM using notepad ++ fixed. I am so pissed off, why isn’t this information more obvious? Irritating as hell.

  127. Gonzalo said on March 30, 2011

    Yeeehaaaaa man… thanks a lot!!!!!

  128. jerry said on April 3, 2011

    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.

  129. Arpan02paliwal said on April 9, 2011

    Its too useful….

  130. Andris Ratnieks said on April 23, 2011

    Thanks! This helped! :)

  131. cax said on May 5, 2011

    thanx dude…easy solution

  132. Zory said on May 30, 2011

    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!

  133. Franz-josef Behr said on June 23, 2011

    Incredible that this problem was caused by the BOM byte….

  134. eden said on June 28, 2011

    same thing.. IDK what to do

  135. im php nppb said on July 4, 2011

    BILLION TONS OF THANK YOU . . . .i loose ALL MY DAY
    thank you thank you thank you

  136. Ioncintea said on July 20, 2011

    Could someone tell me what is wrong with that code

        Hello world!

       

  137. Mgfrias said on August 10, 2011

    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

  138. Truby said on August 13, 2011

    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);
    ?>

  139. Truby said on August 13, 2011

    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”);

  140. Truby said on August 14, 2011

    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?

  141. Truby said on August 14, 2011

    I dint add any DOM elements…

  142. Shan said on September 27, 2011

    Thanks ob_start(); is a magic :)

  143. 2Cool said on October 12, 2011

    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.

  144. Klamber|ext. said on October 13, 2011

    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 :D

    Thanks again! :)

  145. alvin said on October 14, 2011

    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

  146. Treasure said on November 15, 2011

    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.

  147. chudnut said on November 26, 2011

    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 :D

  148. wp lovr said on January 15, 2012

    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…

  149. AdamT said on January 28, 2012

    @aneesniittch is awesome. try this.

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -