Reputation: 13
I have got my login function to work which then has an array to show the session data but when I click logout it redirects me to the login page but does not clear the session data if I manually load up the members page.
Controller Function
public function logout(){
$this->session->sess_destroy();
redirect('site/login');
}
public function members(){
if ($this->session->userdata('is_logged_in')){
$data['title'] = "Members";
$this->load->view('view_header');
$this->load->view("view_members", $data);
}
else{
redirect('site/restricted');
}
}
Model
class Model_users extends CI_Model {
public function canLogin(){
$this->db->where('Username', $this->input->post('Username'));
$this->db->where('Password', md5($this->input->post('Password')));
$query = $this->db->get('user_registration');
if ($query->num_rows() == 1){
return true;
}
else{
return false;
}
}
}
Members View
<?php
echo "<pre>";
print_r ($this->session->all_userdata());
echo "</pre>";
?>
<a href='<?php echo base_url()."index.php/site/logout"?>'>Logout</a>
Not sure what I'm missing here since the logout function runs but doesn't seem to clear the session.
Upvotes: 0
Views: 1645
Reputation: 1040
Try create a function in your Home controller cleaning the cache like this:
function clear_cache()
{
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");
}
So call it from your controller's constructor
class Home extends CI_Controller
{
function __construct()
{
parent:: __construct();
$this->clear_cache();
}
}
Hope it help.
Upvotes: 1