Results 1 to 4 of 4

Thread: set cookie help

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Location
    Dallas, Texas
    Posts
    5

    set cookie help

    hey everyone, i am looking for some help with the set cookies command in PHP. I searched the forum to see what came up and found some help on the error i was getitng but nothing that pertained to my certain sittuation that i could see. I am getting this error:

    Warning Cannot add header information - headers already sent by...

    Now from what i read on this forum this was caused by either a space before or after the set cookie command or output (print , echo etc) before the SetCookie function is executed, but my program has neither of these problems.. here is some of the code (the 3 or 4 lines where the error is occuring):
    PHP Code:
          if($pword==$pass) {
              
    $info="$uname;$pword";
              
    setcookie("User",$infotime()+86400);
             
    ShowForum();
           } 
    Could it be because i am calling the ShowForum function after, i elliminated the $info variable and the ShowForum call to see if that was the cause and i got nothing.. ne suggestions?

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    what ever is above that is messing it up. what is the exact error, it says what line it is happening on. and it is not just spaces, but anything that is echoed out to the browser before that cookie is set will cause the error as well.

  3. #3
    New Member omegatng's Avatar
    Join Date
    Aug 2003
    Location
    Florence, Alabama
    Posts
    11
    You're getting this error because output_buffering is set to off, which means that if you call set_cookie or use any session variables after the output of the page has been started, they don't get set. There's two workarounds for this. Either turn on output_buffering in the php.ini file, then restart apache, or make sure that your code block that sets the cookie appears before ANY output you make, even just an echo statement.
    OCS Solutions, Inc. - Web Hosting, Web Design, Custom Programming
    http://www.ocssolutions.com/

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Is it just me or is the most commonly asked question on these boards?
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width