Hello everybody!
I’m making a small project which requires a user login. Nothing fancy, no user roles. I’ve used CodeIgniter for this before. I just store the username in the session userdata. However I ran into a problem this time.
After login $this->session->userdata(‘username’) is reported as empty every time.
I var_dump $this->session->userdata and I see it is being set in the login method. However after the redirect the username userdata is non-existent. If I check in the database the session is being stored correctly, with the same session ID and the userdata also containing the stuff I expect.
Does anyone have any clues about this? I’ve been stuck at this simple thing for two days!
I forgot to mention that the database is Oracle. I don’t know if this has anything to do with this, but I doubt. The queries run fine and no errors are being reported.
Just for the reference, here’s the login method.
public function login()
{
$this->form_validation->set_rules('username', 'Username', 'required|trim');
$this->form_validation->set_rules('password', 'Password', 'required|trim');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
if ($this->form_validation->run() == false)
{
$data['html_title'] = 'Login';
$this->load->view('auth/login',$data);
} else {
$this->db->where('username',$this->input->post('username'));
$this->db->where('password',md5($this->input->post('password')));
$query = $this->db->get($this->tables['users']);
if ($query->num_rows() == 1) {
$result = $query->row();
$data = array(
'username' => $this->input->post('username'),
'logged_in' => true
);
$this->session->set_userdata($data);
redirect('dashboard');
} else {
$this->session->set_flashdata('message','<div class="error">Error logging in. Check your username and password.</div>');
redirect('auth/login');
}
}
}
Thanks in advance!
