PDA

Click to See Complete Forum and Search --> : set cookie help


black_orb
Jul 30th, 2003, 01:08 AM
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):

if($pword==$pass) {
$info="$uname;$pword";
setcookie("User",$info, time()+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?

phpman
Jul 30th, 2003, 11:16 AM
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.

omegatng
Aug 24th, 2003, 04:50 PM
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.

The Hobo
Aug 25th, 2003, 12:18 PM
Is it just me or is the most commonly asked question on these boards?