Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between 0 and negative value for setMaxAge for Cookie

Tags:

cookies

From cookie docs for setMaxAge(int): http://docs.oracle.com/javaee/1.3/api/javax/servlet/http/Cookie.html#setMaxAge(int) Is there any difference between int = 0 and int = -ve? It says 0 deletes cookie. -ve value means cookie is not stored. Does that mean 0 deletes only from current browser session?

like image 759
Victor Avatar asked Apr 10 '13 17:04

Victor


2 Answers

I suggest you go read about cookies from a browser perspective. It's very interesting. Note that 'max-age' is the newer version of 'expires' and some browsers may not support it. (For example, IE6, IE7, and IE8 don't support max-age.)

0 means delete the cookie right now.

negative means preserve the cookie for a while. I suspect the scope is somewhat browser specific but it will not preserve the cookie across closing and reopening the browser.

like image 169
Lee Meador Avatar answered Oct 27 '22 01:10

Lee Meador


Setting setMaxAge to 0 will delete the cookie. Setting it to -1 will preserve it until the browser is closed.

like image 33
user2644123 Avatar answered Oct 27 '22 01:10

user2644123



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!