Home>

Set the validity period of the cookie object, The setmaxage () method can set the validity time of the cookie object,

E.g:cookie c=new cookie ("username", "john");

c.setmaxage (60);//60 seconds mean

c.setmaxage (60 * 60);//one hour

c.setmaxage (365 * 24 * 60 * 60);//one year

If you do not set an expiration time,It means that the cookie life cycle is during the browser session,Just close the browser window,The cookie disappeared.

This type of cookie with a lifetime of a browsing session is called a session cookie. Session cookies are generally not stored on the hard drive but in memory.

If an expiration time is set,The browser will save the cookie to your hard drive,Open the browser again after closing,These cookies remain valid until the set expiration time.Cookies stored on your hard drive can be shared between different browser processes,For example two ie windows. As for cookies stored in memory, different browsers have different processing methods.

When cookie.setmaxage is set to 0, the specified cookie will be deleted on the browser immediately.

When cookie.setmaxage is set to -1, it means that closing the current browser is invalid.