php - 更新会话销毁数据库
问题描述
首先,我是一名 Laravel 程序员,试图理解这个旧的 codeginiter 系统。我需要避免同一个用户多次登录。我只需要登录一次,没有人可以使用该帐户登录。
我只是设法在 application/controllers/backend/Auth.php 中修改函数 logout()
public function logout() {
$logout = $this->ion_auth->logout();
// 20200117 2355 : agrego |--
$user_x = $this->codegen_model->row('users', '*', "id='" . $this->session->userdata('user_id') . "'");
if( !is_null($user_x) ){
$data = array(
'ip_address' => (binary)''
);
$this->codegen_model->edit( 'users', $data, 'id', $user_x->id );
}
// --|
redirect(base_url() . 'web_ctrl', 'refresh');
}
和 application/models/ion_auth_model.php 中的函数 username_check
/**
* Checks username
*
* @return bool
* @author Mathew
**/
public function username_check($username = '')
{
$this->trigger_events('username_check');
if (empty($username))
{
return FALSE;
}
// 20200117 2355 : agrego |--
$user_x = $this->codegen_model->row('users', '*', "username='" . $username . "'");
if (!is_null($user_x)) {
if( $user_x->ip_address != (binary)'' )
return FALSE;
else {
$data = array(
'ip_address' => (binary) inet_pton($this->input->ip_address())
);
$this->codegen_model->edit('users', $data, 'id', $user_x->id);
}
}
// --|
$this->trigger_events('extra_where');
return $this->db->where('username', $username)->count_all_results($this->tables['users']) > 0;
}
如果表用户中的“ip_address”为空,我只是让用户登录,如果不是,则在 username_check 中阻止(返回 FALSE)。
这有效,但在会话到期时失败(application/controllers/backend/Auth.php logout() 未触发),而是 library/Session/MY_Session sess_destroy() 被触发,但我无法从那里修改数据库:
// 20200117 2355 : agrego |--
class MY_Session extends CI_Session{
public function __construct() {
parent::__construct();
}
function sess_destroy() {
$data = array(
'ip_address' => (string) ''
);
$this->db->update($this->tables['users'], $data, array('id' => $this->session->userdata('user_id')));
//call the parent
parent::sess_destroy();
}
}
// --|
说 $this-->db 为空...
那么,我如何不能在会话到期时修改数据库?
解决方案
看起来您正在使用 ion_auth 脚本...尝试将您的脚本放在注销功能下的 ion auth 库中...这取决于您如何安装 ion_auth 脚本..如果您将其安装为第三方应用程序,那么您可以找到它在第三方文件夹中...查找库文件夹,而不是在其中找到 ion auth 库...打开它并找到注销功能,然后将脚本放在调用 sess_destroy() 之前
推荐阅读
- c# - 模拟 IScheduler 进行单元测试
- java - 为什么这个 Spring 应用程序不起作用?
- java - 无法在选项卡布局中创建动态选项卡
- excel - Excel公式搜索范围内的单词并显示相应的ID
- c - 不知道为什么优化器不正确地优化我的方法
- javascript - 选择由两个不同字段组成的动态 ID
- c# - 窗口标准化时不触发 MouseUp 事件,仅在最大化窗口上触发
- c# - 在 C# 中使用点符号进行插值
- asp.net-core - Steeltoe Serilog 动态记录器在 .net core 2.2 应用程序中不起作用
- python - Matplotlib 和 pandas 中条形图的区别