将 cookie.gc_maxlifetime 延长至一周是实现“记住我”的好主意吗?
cookie.gc_maxlifetime 的默认设置是 24 分钟,所以即使我将 cookie 设置为一周后过期,“记住我”也会工作 24 分钟,所以我考虑延长 gc_maxlifetime,但也许有更好的解决方案?
The default setting of cookie.gc_maxlifetime is 24 minutes, so even if I set the cookie to expire in one week the 'Remember me' will work for 24 minutes so I thought about extending gc_maxlifetime, but maybe there is a better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
垃圾收集器之所以被称为垃圾收集器,是因为它确实收集垃圾:如果您不删除旧的会话文件,那么任何人都可以简单地在您的站点上发出数十亿个 GET / 请求(不保存 cookie),并且您的服务器将生成数十亿个会话文件,而这些文件不会被删除。删除一周 - 它可能会大大减慢您的网站速度,甚至弄乱您的文件系统。如果您想实现“记住我”功能 - 那么您将必须进行自己的垃圾收集(例如来自同一 IP 的会话不超过 100 个等),甚至可能实现您自己的会话处理(例如存储它们)在数据库中以提高会话数据查找速度并为更好的可扩展性做好准备)。
Garbage collector is called that because it really collects garbage: if you don't delete old session files then anyone can simply go billions GET / requests on your site(without saving cookies) and your server will generate billions of session files that will not be deleted for a week - it may slow down your site considerably or even mess with your filesystem. If you want to implement "remember me" feature - then you will have to do your own garbage collection (for example no more then 100 sessions from the same IP, etc.) and maby even implement your own session handling (for example store them in database to increase session data lookup speed and prepare for better scalability).
我想
session.gc_maxlifetime
和也许session.cookie_lifetime
就是你的意思?好吧,你可以这样做,让你的会话持续那么长时间。我不想使用内置的会话处理,而是设置一个具有我想要的生命周期和一些哈希值的 cookie;我会将该哈希值保留在数据库中。
在我看来,“正常”会话持续那么长时间并不是一个好主意,例如出于安全原因。
I guess
session.gc_maxlifetime
and maybesession.cookie_lifetime
is what you mean?Well, you could do it that way, make your session live that long. I would prefer not to use inbuilt session handling, instead I would set a cookie with my desired lifetime and some hash value; and I would persist that hash in a database.
Having a "normal" session last that long is no good idea IMO, e.g. for security reasons.