[eluser]RyanH[/eluser]
I've been trying to figure out why my custom logout function isn't working and I can't seem to figure it out. I realize that my code is probably not the best way to go about doing things, so I'm open to suggestions. I'm still learning my way around CodeIgniter. My code is below so if anybody has any advice, I'd appreciate it. Thanks.
Code:
// Run the validation and if it's not successful return them to the login page
// If the validation is successful, process the login
if($this->validation->run() == FALSE)
{
$this->load->view('login_view');
} else {
$data = array(
'email' => $this->validation->email,
'password' => $this->validation->password
);
$this->db->where(array('email' => $this->validation->email, 'password' => $this->validation->password));
$query = $this->db->get('users');
if($query->num_rows() > 0)
{
/* $newData = array(
'email' => $this->validation->email,
'logged_in' => 1
);
$this->session->set_userdata('email', $this->validation->email); */
$this->load->view('login_complete');
} else {
$this->load->view('login_view');
}
}
}
function logout()
{
$logout = $this->session->sess_destroy();
if($logout)
{
$this->load->view('home_view');
} else {
echo 'Error logging out';
}
}
This is the code on the temporary page that loads if you're login was successful (located at the very top of the page):
Code:
if(!$this->session->userdata('session_id'))
{
redirect('login', 'location');
} else {
echo 'Welcome ' . anchor('login/logout', 'Logout');
}