I have developed a web application using Codeigniter. It all works perfectly on localHost, but now that I uploaded it to a server I have one single issue. Everything works as it's supposed to except my redirect when the user inserts the wrong password. It was supposed to redirect back to login page and display an error message (which works with localhost ), but I get the following errors.
I decided to not redirect and simply load my login view again, it worked, but I still get the Trying to get property of non object error message, which is weird cause I didn't get this error working on localhost.
My controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function index()
{
$this->load->view('header');
$this->load->view('login_view');
$this->load->view('footer');
}
public function to_login() {
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required');
if($this->form_validation->run() == FALSE) {
$data = array(
'errors' => validation_errors()
);
$this->session->set_flashdata($data);
redirect('index.php/Login');
} else {
$email = $this->input->post('email');
$password = $this->input->post('password');
// the following lines are 38 and 39
$user_id = $this->Login_model->login_user($email, $password)->user_id;
$first_name = $this->Login_model->login_user($email, $password)->first_name;
if($user_id) {
$user_data = array(
'user_id' => $user_id,
'first_name' => $first_name,
'logged_in' => true
);
$this->session->set_userdata($user_data);
redirect('http://gc200322197.computerstudi.es/app/index.php/Main');
} else {
$this->session->set_flashdata('login_fail', 'Invalid login. Please check the email and password fields.');
$this->load->view('header');
$this->load->view('login_view');
$this->load->view('footer');
}
}
}
My model:
<?php
class Login_model extends CI_Model{
public function login_user($email, $password) {
$this->db->where('email', $email);
$result = $this->db->get('users');
$db_password = $result->row(4)->password;
if(password_verify($password, $db_password)) {
return $result->row(0);
} else {
return false;
}
}
}
I've read so many questions about this error and I still couldn't figure out what is wrong and why it works on localhost and not online. I'd really appreciate some help on this.