php - Not Logging On In Codeigniter With Custom Validation -



php - Not Logging On In Codeigniter With Custom Validation -

in codeigniter login not having no luck logging on. throws 1 error called. undefined property: error message. not sure if validate right if why not picking user.

error

message: undefined property: ci_db_mysqli_driver::$num_rows

library file

public function login() { $this->ci =& get_instance(); $this->ci->load->library('session'); $this->ci->load->library('security/encryption'); $password = $this->ci->input->post('password'); $username = $this->ci->input->post('username'); $user_query = $this->ci->db->select('*') ->where('username', $username) ->where('password', $this->ci->encryption->hash_password().hash('sha512', $password).$this->ci->encryption->generate_salt()) ->where('status', "1") ->from('user'); if($user_query->num_rows) { $data = array( 'ip' => $this->ci->input->ip_address(), 'user_id' => $this->ci->session->userdata('user_id') ); $this->db->where('user_id', $user_id); $this->db->update('user', $data); homecoming true; } else { homecoming false; } }

i utilize own form validation method rather codeigniter way. way have more command on it.

controller

public function index() { $this->load->library('users'); $this->lang->load('common/login', 'english') if(($this->input->server('request_method') == 'post') && $this->validate()) { $data = array( 'username' => $this->input->post(), 'user_id' => $row->user_id, 'islogged' => true ); $this->db->get('user'); $this->session->set_userdata($data); redirect('dashboard'); } if (array_key_exists('warning', $this->error)) { $data['error_warning'] = $this->error['warning']; } else { $data['error_warning'] = ''; } if (array_key_exists('username', $this->error)) { $data['error_username'] = $this->error['username']; } else { $data['error_username'] = ''; } if (array_key_exists('password', $this->error)) { $data['error_password'] = $this->error['password']; } else { $data['error_password'] = ''; } $data['action'] = site_url("login"); if (!"" == trim($this->input->post('username'))) { $data['username'] = $this->input->post('username'); } else { $data['username'] = ''; } if (!"" == trim($this->input->post('password'))) { $data['password'] = $this->input->post('password'); } else { $data['password'] = ''; } $this->load->view('template/common/login', $data); } protected function validate() { if (!"" == trim($this->input->post('username')) || !"" == trim($this->input->post('password')) || !$this->users->login($this->input->post('username'), $this->input->post('password'))) { $this->error['warning'] = $this->lang->line('error_login'); } homecoming !$this->error; } }

i'm not expert in oop or in codeigniter library doesn't create much sense me.

try doing var_dump() of $user_query->num_rows, query looks it's using ci active record query should this

// build query $this->ci->db->select('*'); $this->ci->db->from('user'); $this->ci->db->where('username', $username); $this->ci->db->where('password', $this->ci->encryption->hash_password().hash('sha512', $password).$this->ci->encryption->generate_salt()); $this->ci->db->where('status', "1"); // execute query $query = $this->ci->db->get(); // thing if ( $query->num_rows() > 0 ) { $data_row = $query->row(); $data = array( 'ip' => $this->ci->input->ip_address(), 'user_id' => $data_row->user_id // don't have user_id in session ); $this->db->where('user_id', $data_row->user_id); // same thing here user_id $this->db->update('user', $data); // should start session here because want login user :) homecoming true; }

i think should trick. using user_id session doesn't exists. in process of loging in can't have user_id in it. way utilize result of query it. should consider of starting session if result true , store info in it.

php codeigniter

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -