7

I know that I can set expiration date for a cookie, but can I make a cookie expire after some time OR when browser is closed?

Jan Żankowski
  • 8,690
  • 7
  • 38
  • 52
Sergej Andrejev
  • 9,091
  • 11
  • 71
  • 108
  • Maybe see also answers of [https://stackoverflow.com/questions/8894243/why-cookies-dont-expire-after-closing-browser](https://stackoverflow.com/questions/8894243/why-cookies-dont-expire-after-closing-browser) and [Wikipedia: HTTP cookie - Expires and Max-Age](https://en.wikipedia.org/wiki/HTTP_cookie#Expires_and_Max-Age). There are two cases of Cookies depending on whether Expires is set or not. If set, make a cookie expire after some time, or expire when browser is closed if not. – samm Apr 28 '21 at 06:58

1 Answers1

12

If you set an expiration date, this will set them to expire on that date, whether the browser is open or closed.

Only non persisted cookies will expire once the browser is closed.

See cookie expiration rules on wikipedia.

Oded
  • 489,969
  • 99
  • 883
  • 1,009