如何更新数据库,当会话自动在codeigniter

如何更新数据库,当会话自动在codeigniter

问题描述:

我正在更新登录和注销日期&登录到我的网站的所有用户的时间,当他们点击登出时,我正在保存该特定用户的注销时间,但何时会话将自动失效,我无法更新注销日期&时间。如何更新数据库,当会话自动在codeigniter

+0

https://stackoverflow.com/questions/29987521/how-to-update-the -database-after-session-is-expired-without-refres –

+0

@ShafiqulIslam我该如何实现与codeigniter相同的功能?在问之前我看过这个问题?你能帮我吗 ? –

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

创建一个PHP文件中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(); 
} 

} 
+0

是的,我做了同样的事情,但表格没有更新 –

+0

$ login_user_id = $ this-> session-> login_user_id; \t $ this-> db-> set('logout_detail_datetime','NOW()',FALSE); \t $ this-> db-> where('login_detail_id',$ login_user_id); \t $ this-> db-> update('login_details'); 我在做// //调用父 parent :: sess_destroy(); –

+0

$ login_user_id = $ this-> session-> login_user_id; $ array = array('logout_detail_datetime'=> NOW()); $ this-> CI-> db-> update('login_details',$ array,$ this-> db-> where('login_detail_id',$ login_user_id));父:: sess_destroy(); –