how to update database table when session expired in codeigniter

夙愿已清 提交于 2020-01-03 03:39:06

问题


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.


回答1:


To do this you have to you have to extend CI_Session

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();
}

}

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



来源:https://stackoverflow.com/questions/21908953/how-to-update-database-table-when-session-expired-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!