问题
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