设置Cookie以永不过期 [英] Set a cookie to never expire

查看:1958
本文介绍了设置Cookie以永不过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看 PHPP设置Cookie的文档,我发现我可以设置cookie的到期日期。您可以将Cookie设置为在浏览器会话结束时或以后的某个时间到期,但我没有看到设置Cookie永不过期的方法。

Looking at the php documentation on setting a cookie I see that I can set an expiration date for the cookie. You can set the cookie to expire at the end of the browser session or at some time in the future but I do not see a way to set the cookie to never expire. Is this even possible and how is this accomplished?

推荐答案

所有Cookie都会根据 Cookie规范,因此这不是PHP的限制。

All cookies expire as per the cookie specification, so this is not a PHP limitation.

使用未来的日期。例如,设置在十年后过期的Cookie:

Use a far future date. For example, set a cookie that expires in ten years:

setcookie(
  "CookieName",
  "CookieValue",
  time() + (10 * 365 * 24 * 60 * 60)
);

请注意,如果您在PHP中设置的日期超过 2038 将环绕,你会得到一个即将过期的cookie。

Note that if you set a date past 2038 in PHP, the number will wrap around and you'll get a cookie that expires instantly.

这篇关于设置Cookie以永不过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆