Change Cookie expiry date - HTTP

2019-02-27 10:35发布

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?

2条回答
Melony?
2楼-- · 2019-02-27 11:16

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=/"
查看更多
乱世女痞
3楼-- · 2019-02-27 11:19

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.

查看更多
登录 后发表回答