即使我的代码工作也无法登录。就像激活= 1一样,它会登录,否则就不会登录。在我的表中激活的行已设置为1,这意味着它已被激活。但我无法登录。它总是输出激活= 0,这是登录失败!请点击您电子邮件地址上的链接!
public function index()
{
$Username=$this->input->post("username");
$Password=$this->input->post("password");
$this->form_validation->set_rules("username", "username", "trim|required");
$this->form_validation->set_rules("password", "password", "trim|required");
$this->db->where('Username', $this->input->post('username'));
$this->db->where('Password', $this->input->post('password'));
$this->db->select('activated');
$que=$this->db->get('tblaccount');
if ($this->form_validation->run()==FALSE)
{
$this->load->view('login_view');
}
else
{
$account=$this->account_model->get_user($Username, sha1($Password));
if (count($account)>0)
{
if ($que->row('activated')==1)
{
$sess_data=array('login'=>TRUE, 'picture'=>$account[0]->Picture, 'firstname'=>$account[0]->First_Name, 'lastname'=>$account[0]->Last_Name, 'id'=>$account[0]->AID, 'position'=>$account[0]->Position, 'department'=>$account[0]->Department);
$this->session->set_userdata($sess_data);
if ($_SESSION['position']=="Professor")
{
echo "<script type='text/javascript'>alert('Welcome to attendance monitoring system, $_SESSION[firstname] $_SESSION[lastname]!');window.location='".base_url("index.php/main")."';</script>";
}
else if ($_SESSION['position']=="Department Chair")
{
echo "<script type='text/javascript'>alert('Welcome to attendance monitoring system, $_SESSION[firstname] $_SESSION[lastname]!');window.location='".base_url("index.php/report")."';</script>";
}
else if ($_SESSION['position']=="OSA Faculty"||"Guidance Faculty")
{
echo "<script type='text/javascript'>alert('Welcome to attendance monitoring system, $_SESSION[firstname] $_SESSION[lastname]!');window.location='".base_url("index.php/faculty")."';</script>";
}
}
else if ($que->row('activated')==0)
{
$this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Login failed! Please click the link on your email address!</div>');
redirect('login');
}
}
else
{
$this->session->set_flashdata('msg', '<div class="alert alert-danger text-center">Wrong Username or Password!</div>');
redirect('login');
}
}
}
答案 0 :(得分:1)
我不明白你代码的一部分。
实际上,您首先放置$this->db->where('Password', $this->input->post('password'));
,然后放置$account=$this->account_model->get_user($Username, sha1($Password));
您应该更正第一个添加:sha1($this->input->post('password'))
,因为我认为实际上您的请求返回一个空行,这就是为什么使用最后一个条件,因为您没有提供其他条件,这是不好的做法PHP。
让我知道!