Re: Cookie -> Delete -> Reset
| From: | Rasmus Lerdorf | Date: | Tue, 09 Jan 2001 17:41:25 +0000 |
| Subject: | Re: Cookie -> Delete -> Reset | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-33502@lists.php.net to get a copy of this message | ||
If you delete and set the cookie on the same request the delete is
completely redundant. It serves no purpose whatsoever because of the way
cookies work and the way browsers accept them. If you do:
setcookie('abc',1);
setcookie('abc',2);
This causes PHP to these headers:
Set-Cookie: abc=1
Set-Cookie: abc=2
The browser will only accept the second one.
However, in general there is nothing wrong with what you are doing. Turn
on your cookie warnings in your browser or telnet to port 80 on your web
server and watch the raw cookies sent by your PHP script. Make sure they
look the way you expect them to.
-Rasmus
On Tue, 9 Jan 2001, Abe Asghar wrote:
> That makes sense Rasmus, but the reason I delete and reset the cookie is
> because I am trying to measure activity and not just a set time. So I have
> the cookie reset every time somebody views a new page. This way it expires
> a set amount of time after they last clicked on a page.
>
> However as you can see this doesn't work. Is there a better way to do this
> anyone knows?
>
> Thanks,
> Abe
>
> ----- Original Message -----
> From: "Rasmus Lerdorf" <rasmus@php.net>
> To: "Abe Asghar" <abe@fish.tm>
> Cc: "PHP General List" <php-general@lists.php.net>
> Sent: Tuesday, January 09, 2001 5:24 PM
> Subject: Re: [PHP] Cookie -> Delete -> Reset
>
>
> > It makes no sense to delete and set. Simply setting it will override the
> > previous. Note also that using such a short expiry time puts you at the
> > mercy of people having the system clocks set correctly. Many people
> > don't. For short expiry cookies, I always do something like:
> >
> >
> > setcookie('user',$user.':'.time()+1500,0,'/','.test.serve.co.uk');
> >
> > That is, put the timestamp in the value field. This timestamp is relative
> > to the system clock on *my* server instead of the remote machine. Then to
> > figure out it the cookie should actually be expired do:
> >
> > list($usr,$ti) = explode(':',$user);
> > if($ti>time()) { ... do whatever you do when a cookie is expired ... }
> >
> > -Rasmus
> >
> > On Tue, 9 Jan 2001, Abe Asghar wrote:
> >
> > >
> > > Hey guys,
> > >
> > > I wonder if U can help...
> > >
> > > I have the following code that reads a cookie and deletes it and then
> resets a cookie of the same name. However all it seems to do is delete the
> cookie and not set a new one. Any ideas what I am missing?
> > >
> > >
> > > $user = $HTTP_COOKIE_VARS["user"];
> > >
> > > setcookie("user");
> > >
> > > setcookie("user","$user",time()+1500,"/",".test.serve.co.uk",0);
> > >
> > >
> > > Thanks in advance,
> > > Abe
> > >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>