PDA

View Full Version : php - setcookie



jetalomar
March 30th, 2004, 23:31
I'm getting an error when I try to set the cookie. For some reason I get this error when I try to set the cookies.
Warning: Cannot modify header information - headers already sent by (output started at /home/mvplea/public_html/index.php:1) in /home/mvplea/public_html/index.php on line 32

and the php code is
if($setuser=="true"){
setcookie("user", $username, time()+(8640000*7),"/"); //will expire in a week
}

bloodyveins
March 31st, 2004, 05:40
Notice the error:

Warning: Cannot modify header information - headers already sent by (output started at /home/mvplea/public_html/index.php:1)

Check the first line of index.php. Make sure there is no white spaces or previously declared: "header()";

jetalomar
March 31st, 2004, 22:51
it doesn't have anything on it and i'm still getting that error.

jetalomar
March 31st, 2004, 23:23
is there a way that I can put the setCookies anywhere on the script?

kabatak
April 1st, 2004, 05:15
Originally posted by jetalomar
is there a way that I can put the setCookies anywhere on the script?
yes, as long as you dont echo() or print() anything before setcookie(); in another words, dont output anything yet until you use setcookie() or header() functions.