2010-07-20 13:29
浏览 1.2k


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?

图片转代码服务由CSDN问答提供 功能建议

查看关于设置cookie的php文档我看到我可以设置cookie的过期日期。 您可以将cookie设置为在浏览器会话结束时或将来的某个时间到期,但我没有看到将cookie设置为永不过期的方法。 这甚至是可能的,这是如何实现的?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

11条回答 默认 最新

  • dongyinzheng6572 2010-07-20 13:35

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

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

      time() + (10 * 365 * 24 * 60 * 60)

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

    解决 无用
    打赏 举报

相关推荐 更多相似问题