I have a table in my database that named history where it logs about login and logout of the users. How can i log in my history table if the user doesn't press my logout button, where it logouts because of session expire or directly closing the page?.
Here is my code in codeigniter logout button:
public function logout(){
$this->load->model('auth/login_model');
$today = date("Y-m-d H:i:s");
$user = array('user_id' => $this->session->userdata['logged_in']['user_id']);
$logdata = array (
'logout_date' => $today,
);
$logout_date = $this->login_model->logout_hist(array('user_id' => $user['user_id']),$logdata);
$this->load->driver('cache');
$sess_array = array(
'username' => '' );
$this->session->unset_userdata('logged_in', $sess_array);
$this->session->sess_destroy();
$this->cache->clean();
redirect('authentication', 'refresh');
ob_clean(); }
how can i make a code to record the autoclose and the autoexpire session as logout datetime in my database?