Reputation: 3425
I have a problem in logout with CI framework. When I logout & press backspace button then it will take me to logged in page.
I need to do refresh manually after logout to destroy session.
Please help me if anybody know.
Here is Code for Logout:
function logout() {
//pr($this->session->userdata[$this->section_name]);
//exit;
$lng = (isset($this->session->userdata[$this->section_name]['site_lang_code']) && $this->session->userdata[$this->section_name]['site_lang_code'] != "") ? $this->session->userdata[$this->section_name]['site_lang_code'] : 'es';
if (isset($this->session->userdata[$this->section_name]['social_login']) && $this->session->userdata[$this->section_name]['social_login'] == 1) {
$this->SocialLogout($this->session->userdata[$this->section_name]['socialgateway']);
}
$this->session->unset_userdata($this->section_name);
redirect(site_url($lng));
exit;
}
Upvotes: 0
Views: 1241
Reputation:
This has to be something with cache control meaning browser caching. I don't think redirect helps. you should disable this and use CodeIgniters Cache Library if any caching is needed.
Add the following to the pages where users are required to be logged in:
//Prevent browsers from using history to browse in the user system.
$this->CI->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->CI->output->set_header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
$this->CI->output->set_header("Pragma: no-cache");
When pressing back in the browser the page will be refreshed.
Upvotes: 1
Reputation: 7240
use redirect()
to go to the main/home page after logout!
$this->session->unset_userdata('login');
redirect('mainController/index', 'refresh');
Upvotes: 0