如何在codeigniter中会话过期时更新数据库表 [英] how to update database table when session expired in codeigniter

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

问题描述

我是新的PHP和Codeigniter,如何更新数据库表在CI的会话过期的地方,我可以把代码?我在数据库中使用uniqid,它被称为令牌。这里是我的登录表用户名,密码,级别,令牌,last_login,exp_time 。并且我想在Codeigniter中的会话过期时更改值token = null。

I'm new in PHP and Codeigniter, by the way how to update database table when session in CI is expired and where I can put the code? I use uniqid in database, it's called token. here is my login tableusername, password, level, token, last_login, exp_time. and I want to change value token=null when session in Codeigniter is expired.

推荐答案

要做到这一点,你必须扩展 CI_Session

To do this you have to you have to extend CI_Session

在application / core / MY_Session.php内创建一个php文件

Create a php file inside application/core/MY_Session.php

class MY_Session extends CI_Session {

public function __construct() {
    parent::__construct();
}

function sess_destroy() {

    //write your update here 
    $this->CI->db->update('YOUR_TABLE', array('YOUR_DATA'), array('YOUR_CONDITION'));

    //call the parent 
    parent::sess_destroy();
}

}

但它可能不总是工作,因为您的Cookie可能会过期,因此CI将无法获取您当前的会话

But it might not always work because your cookie might get expire so CI will not able to get your current session

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

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