Home > tricks > How to declare a cookie that will destroy after browser is closed

How to declare a cookie that will destroy after browser is closed

HI,

I face one problem regarding cookie.Actually, I have to maintain session detail into cookie(rather than session with which i am pretty much used to :) ).My problem was to declare a cookie that will destroy after browser is closed.

Cookie can be expired by using simple cmd:

setcookie("testcookie","",time()-3600);

But if User directly closed the browser…then???

If we set the expire time to 0, makes it a browser session cookie, lasting forever,until the browser is closed.

My fix:

setcookie("testcookie","test",0);

Categories: tricks Tags:
  1. January 8, 2008 at 2:35 am | #1

    very interesting.
    i’m adding in RSS Reader

  1. No trackbacks yet.