如何检查用户是否处于活动状态然后注销
How to check if user is active and then log out
我有一个登录表单并且可以正常工作,但我必须添加用户是否处于活动状态的条件。如果他不活跃,则重定向到某个页面 show_error。我正在使用 CodeIgniter。这是我的模型:我尝试使用此功能 "is_active_user" 但它不起作用。
public function login()
{
$this->db->select('*');
$this->db->from('users');
$this->db->where('username', $this->input->post('username'));
$this->db->where('password',sha1($this->input->post('password')));
$result=$this->db->get();
return $result->row_array();
}
public function is_active_user() {
$this->db->select('*');
$this->db->from('users');
$this->db->where('username', $this->input->post('username'));
$this->db->where('deactivated_at = "0000-00-00 00:00:00" || deactivated_at IS NULL ');
$result=$this->db->get();
if($result->num_rows() > 0)
{
return $result->row_array();
}
return false;
}
我的控制器是:
public function login ()
{
$this->load->model('user_model');
$user=$this->user_model->login();
$is_active=$this->user_model->is_active_user();
$this->form_validation->set_rules('username', 'Потребителско име', 'trim|required|callback_login_check');
$this->form_validation->set_rules('password', 'Парола', 'trim|required');
if ($this->form_validation->run()==FALSE)
{
$this->index();
}
else
{
if(count($user) > 0 && count($is_active) > 0)
{
$this->load->library('session');
$data = array(
'username' => $user['username'],
'user_id' => $user['user_id'],
'is_logged_in' => TRUE,
'role_id' => $user['role_id']
);
$this->session->set_userdata($data);
}
}
}
如何查看用户是否活跃?
但是没有结果。
现在我尝试了:
public function login()
{
$this->db->select('*');
$this->db->from('users');
$this->db->where('username', $this->input->post('username'));
$this->db->where('password',sha1($this->input->post('password')));
$this->db->where('deactivated_at = "0000-00-00 00:00:00" OR deactivated_at IS NULL');
$result=$this->db->get();
return $result->row_array();
}
但它用另一个配置文件记录我,而不是我填写的带有用户名和密码的配置文件。
public function login()
{
$this->db->select('*');
$this->db->from('users');
$this->db->where('username', $this->input->post('username'));
$this->db->where('password',sha1($this->input->post('password')));
$this->db->where('deactivated_at <> "0000-00-00 00:00:00"');
$this->db->where('deactivated_at IS NOT NULL');
$result=$this->db->get();
return $result->row_array();
}
我有一个登录表单并且可以正常工作,但我必须添加用户是否处于活动状态的条件。如果他不活跃,则重定向到某个页面 show_error。我正在使用 CodeIgniter。这是我的模型:我尝试使用此功能 "is_active_user" 但它不起作用。
public function login()
{
$this->db->select('*');
$this->db->from('users');
$this->db->where('username', $this->input->post('username'));
$this->db->where('password',sha1($this->input->post('password')));
$result=$this->db->get();
return $result->row_array();
}
public function is_active_user() {
$this->db->select('*');
$this->db->from('users');
$this->db->where('username', $this->input->post('username'));
$this->db->where('deactivated_at = "0000-00-00 00:00:00" || deactivated_at IS NULL ');
$result=$this->db->get();
if($result->num_rows() > 0)
{
return $result->row_array();
}
return false;
}
我的控制器是:
public function login ()
{
$this->load->model('user_model');
$user=$this->user_model->login();
$is_active=$this->user_model->is_active_user();
$this->form_validation->set_rules('username', 'Потребителско име', 'trim|required|callback_login_check');
$this->form_validation->set_rules('password', 'Парола', 'trim|required');
if ($this->form_validation->run()==FALSE)
{
$this->index();
}
else
{
if(count($user) > 0 && count($is_active) > 0)
{
$this->load->library('session');
$data = array(
'username' => $user['username'],
'user_id' => $user['user_id'],
'is_logged_in' => TRUE,
'role_id' => $user['role_id']
);
$this->session->set_userdata($data);
}
}
}
如何查看用户是否活跃?
但是没有结果。 现在我尝试了:
public function login()
{
$this->db->select('*');
$this->db->from('users');
$this->db->where('username', $this->input->post('username'));
$this->db->where('password',sha1($this->input->post('password')));
$this->db->where('deactivated_at = "0000-00-00 00:00:00" OR deactivated_at IS NULL');
$result=$this->db->get();
return $result->row_array();
}
但它用另一个配置文件记录我,而不是我填写的带有用户名和密码的配置文件。
public function login()
{
$this->db->select('*');
$this->db->from('users');
$this->db->where('username', $this->input->post('username'));
$this->db->where('password',sha1($this->input->post('password')));
$this->db->where('deactivated_at <> "0000-00-00 00:00:00"');
$this->db->where('deactivated_at IS NOT NULL');
$result=$this->db->get();
return $result->row_array();
}