[eluser]Bainzy[/eluser]
Hi everyone,
I have run into a bit of a problem with sessions today, im sure its propbs my code but when i call the session to be destroyed its not clearing the sessions, i am still logged in :S
Here is my code from loggin in :
First my controller :
Code:
function submit_login()
{
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('login');
}
else
{
$username = $this->input->post('username');
$password = dohash($this->input->post('password'), 'md5');
// Returns userid if matched, false if not
$results = $this->MUsers->submit_login($username, $password);
if($results==false)
{
$this->load->view('login');
}
else
{
redirect('forums/topics');
}
}
}
and here is my model
Code:
function submit_login($username, $password)
{
$q = $this->db->get_where('users', array('Username'=>$username, 'Password'=>$password));
if($q->num_rows() == 0)
{
return false;
}
else
{
$results = $q->result();
$data = array (
'userid' => $results[0]->UserID,
'username' => $results[0]->Username,
'logged_in' => TRUE,
);
$this->session->set_userdata($data);
return true;
}
}
I am checking if the user is logged in by using this code :
Code:
if($this->session->userdata('logged_in') == FALSE)
{
// Login link here
}
else
{
// Welcome code here
}
and my logout code in my controller
Code:
function logout()
{
$this->session->unset_userdata(array('logged_in'=>''));
redirect('forums/topics');
}
Can anyone see where i am going wrong ?
Regards
Chris