Re: cookie help

From: Date: Wed, 25 Jul 2001 00:30:05 +0000
Subject: Re: cookie help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-59463@lists.php.net to get a copy of this message
> in order to prevent my visitors from seeing more than one popup in less than > 120 second, I added this to my php page(index.php) > -------------- > setcookie("popup",1,time()+120); > if ($popup!=1) > > echo "<script > src=http://www.peel.net/frames/PMNforce.js></script>"; > } > ------------- > > When I reload index.php, i see popups everytime. I am pretty sure that I > enabled cookies in IE and Netscape. > > Please help. thanks Do you really think that people will have their system clocks set accurately to within 120 seconds of your server's system clock? Heck, you are lucky if they have their clock set to the right year, never mind the right date and time down to the minute. To do this reliably, encode your system time in the cookie value and use that to determine whether the cookie is valid. And use a session cookie. Like this: $value = 1; $time = time() + 120; setcookie('popup',"$time:$value"); if(isset($popup)) { list($time,$value) = explode(':',$popup); if($time > time()) $popup = false; else $popup = true; } if($popup) echo "<script src=http://www.peel.net/frames/PMNforce.js></script>"; -Rasmus

« previous php.general (#59463) next »