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?
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.
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.
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.
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.
oh... this is because I activated "Continue where I left off" in chrome://chrome/settings/.
See here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With