Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setcookie with expire=0 does not expire after the browser closes

I use setcookie to make a cookie with expire=0. From the PHP document, (link)

The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number ?of seconds before you want it to expire. Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).

My php code:

setcookie('option', 'yes', 0, '/');

However, the cookie does still not expire (still can be accessed) when I close and re-open the browser(chrome but not firefox).

How do I make the cookie expires when the browser is closed?

like image 634
Timespace7 Avatar asked Jun 15 '13 13:06

Timespace7


People also ask

Can you set a cookie to never expire?

Disclaimer: All the cookies expire as per the cookie specification. So, there is no block of code you can write in JavaScript to set up a cookie that never expires. It is just impossible and is a fact.

What happens when cookie expires in browser?

Cookies with an expiration date in the past will be removed from the browser. To remove a cookie, you must set it's set its expiration date in the past. This will signal to the browser that the cookie should be removed.

How do I set my cookie lifetime?

You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the 'expires' attribute to a date and time.

Does expired cookie get deleted?

If a cookie has expired, the browser does not send that particular cookie to the server with the page request; instead, the expired cookie is deleted.


1 Answers

oh... this is because I activated "Continue where I left off" in chrome://chrome/settings/.

See here

like image 143
Timespace7 Avatar answered Oct 24 '22 00:10

Timespace7