【问题标题】:How to update database when session expires automatically in codeigniter如何在codeigniter中会话自动过期时更新数据库
【发布时间】:2017-05-25 05:37:43
【问题描述】:

我正在更新登录我网站的所有用户的登录和注销日期和时间,当他们当时单击注销时,我正在保存该特定用户的注销时间,但是当会话自动到期时,我无法更新注销日期和时间。

【问题讨论】:

标签: php codeigniter session session-timeout


【解决方案1】:

为此,您必须扩展 CI_Session

application/core/MY_Session.php内创建一个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();
}

}

【讨论】:

  • $login_user_id=$this->session->login_user_id; $this->db->set('logout_detail_datetime', 'NOW()', FALSE); $this->db->where('login_detail_id', $login_user_id); $this->db->update('login_details');我正在这样做 //调用父 parent::sess_destroy();
  • $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();
  • 好的,我试试这个?它真的会产生一些不同吗?
  • 是否需要更改配置文件中的任何内容>
  • 您可能还想在 config/autoload.php 中添加“会话”:$autoload['libraries'] = array('session',....)
猜你喜欢
  • 1970-01-01
  • 2023-03-17
  • 2013-04-04
  • 1970-01-01
  • 2023-03-21
  • 2013-09-15
  • 2015-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多