2017-05-25 47 views
1

我正在更新登錄和註銷日期&登錄到我的網站的所有用戶的時間,當他們點擊登出時,我正在保存該特定用戶的註銷時間,但何時會話將自動失效,我無法更新註銷日期&時間。如何更新數據庫,當會話自動在codeigniter

+0

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

+0

@ShafiqulIslam我該如何實現與codeigniter相同的功能?在問之前我看過這個問題?你能幫我嗎 ? –

回答

0

要做到這一點,你必須你必須擴展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(); –