codeigniter - Failed to login using php -
i using php codeigniter framework. here login.php controller.
public function index() { if($this->input->post('login') == 1) { $user = new users_model(); $user->email = $this->input->post('email'); $user->password = $this->input->post('password'); $user->user_role = $this->input->post('user_role'); $results = $this->usermodel->login($user); if(count($results)>0) { if(is_array($results) || is_object($results)) { foreach($results $row) { $session_array = array( "id" => $row['id'], "username" => $row['username'], "email" => $row['email'], "password" => $row['password'], "image" => $row['image'], "description" => $row['description'], "account_status" => $row['account_status'], "user_role" => $row['user_role'] ); $this->session->set_userdata($session_array); $url = base_url() . "home?login=success"; redirect($url, "refresh"); } } }else{ $url = base_url() . "login?login=failed"; redirect($url, "refresh"); } }else{ $this->load->view('login-page'); } }
here users_model.php in model.
function login($user){ $conditions = array( "email" => $user->email, // "password" => $user->password, "user_role" => $user->user_role, "account_status" => 1, ); $this->db->select('*'); $this->db->from('users'); $this->db->where($conditions); $rs= $this->db->get(); if(!empty($rs)){ $result_array = $rs->row_array(); if(password_verify($user->password,$result_array['password'])){ return $result_array; } } return false; }
is password_hash , password_verify correctly? , below error code:
severity: warning
message: illegal string offset 'id'
filename: controllers/login.php
line number: 38
and other string in session_array
remove foreach loop , fine
public function index() { if($this->input->post('login') == 1) { $user = new users_model(); $user->email = $this->input->post('email'); $user->password = $this->input->post('password'); $user->user_role = $this->input->post('user_role'); $results = $this->usermodel->login($user); if(count($results)>0) { if(is_array($results) || is_object($results)) { $session_array = array( "id" => $results['id'], "username" => $results['username'], "email" => $results['email'], "password" => $results['password'], "image" => $results['image'], "description" => $results['description'], "account_status" => $results['account_status'], "user_role" => $results['user_role'] ); $this->session->set_userdata($session_array); $url = base_url() . "home?login=success"; redirect($url, "refresh"); } } else { $url = base_url() . "login?login=failed"; redirect($url, "refresh"); } } else { $this->load->view('login-page'); } }
Comments
Post a Comment