How to Make Browsers Delete Specific Cookies

本文探讨了频繁更新Cookies的方法,包括覆盖原有Cookies及删除过期Cookies的实践。文章引用了Wiki和MSDN的说明,强调了匹配Path和Domain属性的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am working on a project which needs to update cookies very frequently. I tried overwrite previous cookie with a new one has the same key, but failed. Then I tried "delete" outdated cookies by re-Set-Cookie a same cookie with expires on tail whose value is the time request arrives, failed again.

 

Wiki says : With an expiration time in the past, the browser will delete this cookie right away – note that cookie will only be deleted when the domain and path attributes in the Set-Cookie header match the values used when the cookie was created .

 

MSDN says : You cannot directly delete a cookie on a user's computer. However, you can direct the user's browser to delete the cookie by setting the cookie's expiration date to a past date. The next time a user makes a request to a page within the domain or path that set the cookie , the browser will determine that the cookie has expired and remove it.

 

 

So the point is Path and Domain have to match, then browsers WILL clear outdated cookies.

 

 

 

 

 

 

 

Creative Commons License
本作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议 进行许可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值