Re: cookie help
| From: | McShen | Date: | Wed, 25 Jul 2001 02:09:58 +0000 |
| Subject: | Re: cookie help | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-59481@lists.php.net to get a copy of this message | ||
thanks!
"Rasmus Lerdorf" <rasmus@php.net> wrote in message
news:Pine.LNX.4.33.0107241724430.1082-100000@rasmus.php.net...
> > 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ô\è
> ›-q¶w3ÞüØ‘></script>";
>
> -Rasmus
>