如何测试 Perl CGI::Cookie cookie 是否即将过期?
如果 cookie 距离过期还有 0
到 x
分钟,我想将该 cookie 的 expires
值刷新为某个设定值(如果cookie已经过期,我不想刷新它)。
我如何使用 CGI::Cookie
和 CGI.pm
来完成此任务?
If the cookie is between 0
and x
minutes away from expiration, I would like to refresh the expires
value of that cookie to some set value (if the cookie is already expired, I do not want to refresh it).
How would I accomplish this with CGI::Cookie
and CGI.pm
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览器发送的 Cookie 不会暴露其过期时间;它们要么已发送,要么没有发送。要知道它何时过期,您必须以某种可解析的形式将过期时间存储在 cookie 值中。
Cookies sent by the browser do not expose their expiration time; they are either sent or they aren't. To know when it is going to expire, you have to store the expiration time in the cookie value in some parseable form.
如果cookie已设置,那么它将被发送到服务器。如果已经过期了,那就不会了。
只需测试一下cookie是否存在,如果存在则刷新即可。
If the cookie has been set, then it will be sent to the server. If it has expired, then it won't be.
Just test to see if the cookie exists, and refresh it if it exists.