note 35791 modified in function.setcookie by pollita

From: Date: Mon, 15 Sep 2003 03:18:25 +0000
Subject: note 35791 modified in function.setcookie by pollita
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-56496@lists.php.net to get a copy of this message
I finally solved a huge problem I was having. I was setting a cookie using setcookie() like this: setcookie ('mycookie','$cookievalue'); and I was wondering why my script kept saying that the cookie was invalid. Finally I debugged and discovered that the value of $HTTP_COOKIE_VALS['mycookie'] was $cookievalue. Like all such occurances, this one hit me like a bolt out of the blue. OF COURSE! I screamed - The browser doesn't know the value of my variable - or even that it is a variable. Never use SINGLE quotes around your PHP variables in the second argument of the setcookie() function. They won't get interpolated, and you will be scratching your head like I was. --was-- I finally solved a huge problem I was having. I was setting a cookie using setcookie() like this: setcookie ('mycookie','$cookievalue'); and I was wondering why my script kept saying that the cookie was invalid. Finally I debugged and discovered that the value of $HTTP_COOKIE_VALS['mycookie'] was $cookievalue. Like all such occurances, this one hit me like a bolt out of the blue. OF COURSE! I screamed - The browser doesn't know the value of my variable - or even that it is a variable. NEVER use quotes around your PHP variables in the second argument of the setcookie() function. They won't get interpolated, and you will be scratching your head like I was. http://www.php.net/manual/en/function.setcookie.php

« previous php.notes (#56496) next »