Re: newbie cookie problem

From: Date: Fri, 28 Jul 2000 15:40:20 +0000
Subject: Re: newbie cookie problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-8798@lists.php.net to get a copy of this message
Rod Goodwin wrote: > > Hi, > I can't get a cookie dropped onto my machine by executing the following > code. > I can echo back $cart_id no problem, but the cookie doesn't show up. > Thanks! > > <? require("config.ini"); > > if(!isset($cartID)) { > > // generates cart id number > $cart_id = md5(uniqid(rand())); > SetCookie("cartID",$cart_id,time()+3600,"/","$SERVER_NAME"); > } > > echo "<form><input name=\"cartID\" type=hidden > value=\"$temp_cart\"></form>"; $cartID won't be available from a cookie until the _next_ time some communication happens with the server. If you need the value of $cardID available to you on the same page where you set the cookie, do something like: if(!isset($cartID)) { // generates cart id number $cart_id = md5(uniqid(rand())); SetCookie("cartID",$cart_id,time()+3600,"/","$SERVER_NAME"); $cartID = $cart_id; } so that until you can grab $cartID from the cookie, you've got the value for use on this page. - julie +------------------------------------------------+ | Julie Meloni (jcm@i2ii.com) | | Tech. Director, i2i Interactive (www.i2ii.com) | | | | "PHP Essentials" & "PHP Fast & Easy" | | http://www.thickbook.com/ | +------------------------------------------------+

« previous php.general (#8798) next »