Error:"Cannot modify header information" why?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luke14free
    New Member
    • Apr 2007
    • 79

    Error:"Cannot modify header information" why?

    Do you know why do I get that message when i type a normal setcookie function??

    Warning: Cannot modify header information - headers already sent by (output started at c:\programmi\ea syphp1.8\www\ho me.php:5) in c:\programmi\ea syphp1.8\www\fu nctions.php on line 92

    Thanks
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Originally posted by luke14free
    Do you know why do I get that message when i type a normal setcookie function??
    Yes.

    For five dollars.

    hehe just kidding there.

    You're getting that message because your script is outputting something before that statement, specifically on line 5.

    Move your setcookie statement to the top of your script (or as close to the top as you can logistically keep it) and eliminate any HTML and/or whitespace before your opening <?php tag.

    Comment

    • luke14free
      New Member
      • Apr 2007
      • 79

      #3
      Eheh! five dollars is too much :D
      Thanks dude. I resolved that problem using sessions.
      Bye!

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        Just thought I should add this.

        Seing as this error is caused because you have already sent the headers to the browser, you can avoid this error by buffering the output and releasing it only when you are ready, using the ob functions.

        For example:
        [code=php]
        ob_start();
        echo "Hello";
        header("Content-type: text/html");
        ob_end_flush();
        [/code]

        Without the ob functions this code would produce the error you encountered.

        Comment

        Working...