CodeIgniter扩展用户的会话过期时间 [英] CodeIgniter extend user's session expiration time
问题描述
可以在CI中扩展用户的会话过期时间。我想要做的是,默认情况下,每个用户的会话cookie持续例如1天,但每次用户访问该网站,他的会话过期时间延长一天。
Is it possible to extend user's session expiration time in CI. What I want to do is, by default every user's session cookie lasts for example 1 day, but every time user visits the site his session expiration time is extended by one more day.
我不知道这是否是一个好主意,也许我应该设置cookie的生命时间为一个星期,这是吗?
I don't know if it is a good idea to do this, maybe I should just set cookies life time for like a week and that's it?
推荐答案
我相信你想要的实际上是默认行为。
查看/system/libraries/Session.php中的sess_read()和sess_update()
I believe what you want is actually the default behavior. Take a look at sess_read() and sess_update() in /system/libraries/Session.php
last_activity为活动会话每五分钟更新一次。
last_activity for an active session is updated every five minutes.
使用last_activity + sess_expiration检查会话到期日期<现在
Session expiration is checked with last_activity + sess_expiration < now
所以,对于你想要的行为,只需将你的sess_expiration时间设置为86400(一天),你应该都设置。
So, for the behavior you want, just set your sess_expiration time to 86400 (one day), and you should be all set.
这篇关于CodeIgniter扩展用户的会话过期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!