如何在codeigniter会话过期时执行一个函数 [英] How to exec a function when codeigniter session expires

查看:169
本文介绍了如何在codeigniter会话过期时执行一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的数据库上有一个在线字段的用户表,它在用户登录时获取值1,并在用户注销时更改为0。问题是,如果用户关闭选项卡,而不点击注销按钮,他会永远保持在线。

I got an users table on my database with a "Online" field, it gets the value "1" when the user loggin, and changes to 0 when the user logout. The problem is that if the user close the tab and don't click on the "Logout" button he stays Online forever.

所以我想挂钩某种函数,所以当会话过期时,它将此在线字段的值更改为0。

So I would like to hook some kind of function so when the session expires it changes the value of this "Online" field - on the database - to "0".

因为我不是什么是正确的方法。

I'm open to suggestions of course, because I don't what is the right approach for this.

推荐答案

将在线字段更改为datetime字段,

Change the online field into datetime field,

字段,使用一个中央控制器,你可以扩展,或使用一个钩子触发每次有一个请求的字段更新(你可以把代码放在会话验证函数,以确保用户登录

Update the field using a central controller you're extending from, or use a hook to trigger the update of the field each time there's a request (You may put the code in the session validation function that you use to make sure a user is logged-in before triggering actions).

然后,您可以使用timediff SQL函数查看用户是否处于活动状态。

Then you can use the timediff SQL function to see if the user is active or not.

这篇关于如何在codeigniter会话过期时执行一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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