Use CI to write the login code, with $this->db->where query the database to verify the account password is always empty return value
The following are the function codes that are validated in the controller:
public function validate_credentials(){ $this->load->model('Bookmark_models'); $query = $this->Bookmark_models->where(); if ($query){ $data = array('username' => $this->input->post('username'), 'is_loggrd_in' => true); $this->session->set_userdata($data); $this->load->view('logged_in_area'); }else { $this->login(); }
The following is the code in the model:
public function where(){ $this->db->where('username',$this->input->post('username')); $this->db->where('passwd',sha1($this->input->post('password'))); $query = $this->db->get('user'); if ($query->num_rows == 1){ return true; }
Reply content:
Use CI to write the login code, with $this->db->where query the database to verify the account password is always empty return value
The following are the function codes that are validated in the controller:
public function validate_credentials(){ $this->load->model('Bookmark_models'); $query = $this->Bookmark_models->where(); if ($query){ $data = array('username' => $this->input->post('username'), 'is_loggrd_in' => true); $this->session->set_userdata($data); $this->load->view('logged_in_area'); }else { $this->login(); }
The following is the code in the model:
public function where(){ $this->db->where('username',$this->input->post('username')); $this->db->where('passwd',sha1($this->input->post('password'))); $query = $this->db->get('user'); if ($query->num_rows == 1){ return true; }
Use echo $this->db->last_query();
the output native SQL statement to execute in the database to see if there is any result.
num_rows()
is a method rather than a property
In addition, it is not recommended that you write this, the model is not recommended to do the controller.
public function login($user, $password) { return $this->db->where('username', $user) ->where('password', sha1($password)) ->get('user') ->row(); }
public function where(){ $this->db->where('username',$this->input->post('username')); $this->db->where('passwd',sha1($this->input->post('password'))); $query = $this->db->get('user'); echo $this->db->last_query();exit(); if ($query->num_rows() ){ return true; } return false;