Reputation: 41
If I click logout link, it will be directed me to the 'logout' function that will destroy the login session. After that I logged in again that directed me to the 'products' function. But if I click back button it will directed me to the 'logout' function, and destroyed login session without clicking the logout link.
logout function->products function->back to the logout by clicking the back button->login session destroyed.
function logout(){
$array_items = array('is_logged_in' => FALSE);
$this->session->unset_userdata($array_items);
$this->products();
}
how can I prevent the page to back to the 'logout' ? if it was possible, I would like to reload the current page rather than just prevent the page to go back.
Thank You so much for your help, and to share you knowledge. Sorry for my bad explanation
Upvotes: 0
Views: 1357
Reputation: 2257
If you have an admin controller or something similar extending CI_CONTROLLER for your users types, I just throw this into the extended controller file:
function __construct() {
parent::__construct();
//check login, redirect if logged in or logging out
$this->no_cache(); //runs if not logging out or logged in
}
protected function no_cache(){
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0',false);
header('Pragma: no-cache');
}
Upvotes: 0
Reputation: 3743
You can use redirect('controller/products');
instead of $this->products();
at the end of your function after the user have clicked the logout function url, in other functions, you need to check if the user has already been logged in or not.
In your case, your url will be /logout
, after redirecting, your url will be /products
.
So, when user clicks back, you will return to the current page and not the logout page.
Upvotes: 1