Fixing PHP Warning - 'Cannot modify header information'

Discussion in 'PHP' started by Silver89, Dec 5, 2011.

  1. #1
    I run a large site with many php files and my error_log is being filled with hundreds of thousands of lines of the following:

    "Cannot modify header information - headers already sent in Unknown on line 0"
    Code (markup):
    I know what usually causes the issue and have checked the start of all php files with a hex editor to remove any utf8 characters.

    I have also checked all headers and setcookies are before any text output on all pages.

    What makes it strange is the error/warning is never output on the screen yet it's appearing thousands of times an hour for all users. I'm really struggling to find this, does anyone have any ideas on what else could be causing it? Does that fact that it's unknown on line 0 help at all?


    EDIT

    This warning does not occur if the following line is commented out:

    
    php_value output_handler ob_gzhandler
    
    Code (markup):
    but why would this cause the above warnings?
     
    Silver89, Dec 5, 2011 IP
  2. jenokz

    jenokz Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    edit your php.inichangedisplay_errors = Offanddisplay_startup_errors = Offboth off
     
    Last edited: Dec 5, 2011
    jenokz, Dec 5, 2011 IP
  3. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #3
    Will that just stop the errors being logged?
     
    Silver89, Dec 5, 2011 IP
  4. jenokz

    jenokz Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    log_errors = On to offBut I think you should just change the error_reporting instead of change log_errors to off
     
    Last edited: Dec 5, 2011
    jenokz, Dec 5, 2011 IP
  5. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #5
    But I want to try and locate the source of the problem instead of simply stopping the errors being displayed.
     
    Silver89, Dec 5, 2011 IP
  6. jenokz

    jenokz Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #6
    is that all same error in all pages "Unknown on line 0" ?
     
    jenokz, Dec 5, 2011 IP
  7. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #7
    The error doesn't appear on any pages it's only in the log every few seconds ..

     
    Silver89, Dec 5, 2011 IP
  8. jenokz

    jenokz Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    change your error_reporting to E_ALL and restart webserver, you should be able to see which file access and contain that error
     
    jenokz, Dec 5, 2011 IP
  9. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #9
    It still shows exactly the same, I sometimes get a referrer but this doesn't help find what's causing the problem.
     
    Silver89, Dec 5, 2011 IP
  10. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #10
    If I comment this line out in .htaccess the error stops?

     
    Silver89, Dec 5, 2011 IP
  11. Rising_Star

    Rising_Star Active Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #11
    Try this.... Write ob_start(); at the very first line of your php page and write ob_flush(); on the same page where your php code ends
     
    Rising_Star, Dec 5, 2011 IP
  12. ATmega Media

    ATmega Media Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Additionally, are you sure the file has not been saved as UTF-8 w/ BOM ?
     
    ATmega Media, Dec 5, 2011 IP
  13. nikunj.akhenia

    nikunj.akhenia Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Put at starting
    ob_start();
     
    nikunj.akhenia, Feb 3, 2012 IP