1
我有一个登录表单并且它可以工作,但如果用户处于活动状态,我必须添加条件。如果他不活跃,则重定向到某个页面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();
}
但它记录了我与其他的个人资料,不在此配置文件与用户名和密码,我已经填补。
谢谢,这个函数更好,而不是另写一个。 :) –
没问题。我很高兴能够提供帮助。 – Tpojka
我编辑了我的问题,我不知道为什么当我使用此代码时,我使用另一个配置文件登录,而不是使用我键入的用户名和密码登录。 –