Reputation: 908
I had a problem with redirecting. I'm using Williams template library.Everything works find except redirecting. The home page still can be accessed by the user after they click log out button. here is my code:
the Page controller:
class Page extends CI_Controller {
function index()
{
$this->load->helper('form');
$this->template->write_view('header','header');
$this->template->write_view('content','login');
$this->template->write_view('sidebar','sidebar');
$this->template->render();
}
}
Home controller:
class Home extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->model('user_model','check',TRUE);
if(!$this->check->checkUserLogin())
{
redirect('page');
}
}
function index()
{
$this->template->write_view('header','header');
$this->template->write_view('content','home');
$this->template->write_view('sidebar','sidebar');
$this->template->render();
}
}
I already kill the session, but when user click 'back' button, the home page still can be viewed. but if the user refresh the page, then the code work as expected.
please help
Upvotes: 1
Views: 504
Reputation: 589
You may try using one of the two following lines of code in your html's head section:
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
OR
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
Essentially these do the same thing. The one down side to this is that unless the content of your website changes with every page load then the user is having to reload the pages every time instead of taking advantage of the speed afforded by the browser's caching mechanism. You'll have to make the decision as to how important it is to prevent the back button issue you described. Keep in mind that if the person closes their browser or the browser is left sitting for long enough before the back button is pressed you will likely find that this issue is non-existent.
Upvotes: 2