Change Cookie expiry date - HTTP

2019-02-27 11:25发布

问题:

I need to change the expiry date of a Cookie that I occasionally set.

More precisely I would like to refresh the expiry date to +1 hour.


This is how I set the cookie

Set-Cookie: test=123; Expires=Wed, 02 Feb 2011 12:00:00 GMT

Setting the cookie again adds another cookie with the same name :S


Any ideas?

回答1:

You can only overwrite a cookie if you use the same parameters (i.e. Domain, Path, Secure, and HTTPOnly).

So to overwrite your current cookie, you need to set it from the same domain and path.



回答2:

If the match is present and unique, this works to set expiration to end of session:

document.cookie="meteor_login_token="+/meteor_login_token=([^;]*)/.exec(document.cookie)[1]+";path=/"