Warning: Cannot modify header information

Discussion in 'PHP' started by cmpolis, Jan 20, 2006.

  1. #1
    Hello everyone,
    I put in an include_once "file.inc", but I get this warning about 10 times:

    Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/r/e/freepr0xy/html/PHProxy.class.php:151) in /home/content/f/r/e/freepr0xy/html/PHProxy.class.php on line 934

    Why is this and how can I fix it or turn of php warnings?

    Thanks
     
    cmpolis, Jan 20, 2006 IP
  2. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You are sending some output to the browser before the headers are outputted. The headers should be the first things to be outputted to the browser.

    Try fixing the above or add ob_start(); right at the top of your script and ob_flush(); at the bottom.
     
    dave487, Jan 20, 2006 IP
  3. fryman

    fryman Kiss my rep

    Messages:
    9,604
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    370
    #3
    dave487, could you give more details? You mean right after the <? php part? So it would look like
    <?php ob_start();
    bla bla
    bla bla
    ob_flush(); ?>

    What does this do?
     
    fryman, Jan 20, 2006 IP
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Move file.inc down below where the first headers are printed. Where depends on the rest of the script.

    http://uk.php.net/ob_start

     
    T0PS3O, Jan 20, 2006 IP
  5. fryman

    fryman Kiss my rep

    Messages:
    9,604
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    370
    #5
    And the way I put it would be correct? Does it work with any php script? I am getting this error also and would like to try the fix
     
    fryman, Jan 20, 2006 IP
  6. dotboost

    dotboost Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    take a look in PHProxy.class.php at line 151 and see what is sent to the browser, some spaces, maybe an empty row or something.
     
    dotboost, Jan 20, 2006 IP
  7. beeweb

    beeweb Peon

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Perhaps there's an empty line or space at the bottom of the script, below or behind the ?>. Get rid of that empty space or line and try again. Most of that problems are caused by lousy text editors which add an empty line at the end.
     
    beeweb, Jan 21, 2006 IP
  8. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #8
    The way you put it is correct and it works with any php script as far as I know.

    Not entirely sure what it does - the only noticeable effect for me is that the error message disappears :)
     
    dave487, Jan 22, 2006 IP
  9. Important

    Important Peon

    Messages:
    87
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    When you use ob_start(), the output content is stored in an internal buffer rather than sending it to the client. If you use ob_end_clean() the buffer is emptied. And if you use ob_end_flush() it sends out what the buffer had, to the browser.

    You can read more about it at the link specified by T0Ps ..
     
    Important, Jan 22, 2006 IP
  10. JoshyD

    JoshyD Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I am having this problem too but none of your above solutions are working for me.
    Anybody know why?

    http://joshyd.dansgalaxy.co.uk
     
    JoshyD, Mar 25, 2007 IP
  11. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #11
    krakjoe, Mar 25, 2007 IP
  12. Your Content

    Your Content Banned

    Messages:
    1,096
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Sometime the error is one or two rows above or below the actual line displayed, depends where an array starts, some others headers are sent twice, once in an included file and once inside the main script so I would look at that too.

    Adding error_reporting(0); in the first line after <?php turns off errors, but if your script can't be executed due to such error, like occurs with that of JoshyD, you will get a blank page instead of stop printing errors.
     
    Your Content, Mar 25, 2007 IP
  13. dotboost

    dotboost Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    the problem is in your index.php at line 2 or 1. remove any blank spaces or blank rows above opening tag <?php
    Also , post the first lines of your index.php file.
     
    dotboost, Mar 25, 2007 IP