"Warning: Cannot modify header information" error, wtf?

Discussion in 'PHP' started by relixx, Feb 8, 2007.

  1. #1
    I recently uploaded a script and while it ran perfectly on my machine when I tried running it on the site it started generating the following error:

    Warning: Cannot modify header information - headers already sent by (output started at /home/[site]/public_html/nediting.php:14) in /home/[site]/public_html/nediting.php on line 224

    (I removed the site's name from the directory path :p)

    Im at a loss as apparently it's caused by blank spaces/lines outside the PHP code, except I don't have any....

    Does anyone know what the hell is going on?
     
    relixx, Feb 8, 2007 IP
  2. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Show us the code above where header() is called.

    Hmm... are you sure your not echo'ing / printing out any html before the use of header() ?

    :)
     
    chopsticks, Feb 8, 2007 IP
  3. adiace

    adiace Active Member

    Messages:
    313
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Something has to be being sent to the browser before that header is called for you to be getting that error. Even a <title> or <meta> tag will not allow the header to be sent... even though you won't see anything on the page.
     
    adiace, Feb 8, 2007 IP
  4. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    The fact that the script ran "perfectly" on your local machine is most probably
    simply because the PHP setting on your local machine is set not to display warnings (check the values for 'error_reporting') or not to display any errors at all (check 'display_errors', 'display_startup_errors')

    My suggestion is, trust the error message and check what is output on the line suggested. It may not be something you echo or print, but could also be another warning/notice/error message.

    Also, set your development environment to be as verbose as possible in reporting errors - so that you can notice small mistakes that may lead to bigger ones, and your production server as quiet as possible - to avoid it revealing sensitive info (e.g. file paths) that may open a security hole.
     
    phper, Feb 8, 2007 IP
  5. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #5
    Put

    ob_start();

    right after PHP start tag, as

    <?
    ob_start();
    
    // remaining code goes here
    
    ?>
    PHP:
    Your problem will be solved :)
     
    designcode, Feb 8, 2007 IP
  6. relixx

    relixx Active Member

    Messages:
    946
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    70
    #6
    Ah, found out what the problem was. Just above line 14 there was some html code, whoops :eek:

    Thanks for the assisance though, I'll keep your suggestions in mind for next time :)
     
    relixx, Feb 9, 2007 IP
  7. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #7
    Also keep in mind that windows behaves differently to linux and production environments, when you're authoring stuff, it's a good idea to author on the OS you're going to use in production if possible, if not, open your php.ini and set all error reporting to the screen or logs so you know before you upload if something is wrong.
     
    krakjoe, Feb 9, 2007 IP