Reputation: 129
I have placed below codeigniter code for controller and view.When a user logout the back button should not go to previous page.But i my case it moves to previous page.Pls help me to solve the issue.
Controller login:
function index()
{
$data['main_content'] = 'login_form';
$this->load->view('includes/template', $data);
}
function logout()
{
$this->session->sess_destroy();
$this->index();
}
view:login_form
<html>
<head>
<SCRIPT type="text/javascript">
window.history.forward();
function disableBack()
{
window.history.forward();
}
</SCRIPT></head>
<title>login_form</title>
<BODY onload="disableBack();" onpageshow="if(event.persisted) disableBack();"><div class="container">
<div class="row">
<div class="span4 logo">
<img src="<?php echo base_url('img/logosl.png'); ?>" style="margin-bottom:7px; margin-top:7px;"/>
</div>
<?php $this->load->view('includes/header'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style1.css" />
<div id="login_form">
<h1>Login!</h1>
<?php
echo form_open('login/validate_credentials');
echo form_input('username', 'Username');
echo form_password('password', 'Password');
echo form_submit('submit', 'Login');
echo anchor('login/signup', 'Create Account');
echo form_close();
?>
</div><!-- end login_form-->
<?php $this->load->view('includes/footer'); ?>
</body>
</html>
Upvotes: 1
Views: 3919
Reputation: 33
Instead of disabling back functionality you should check user's authentication on your application's pages (i.e check whether the user has logged in from login page and user has proper keys or not) if he doesn't that he should be redirected to the login page. You could do this by applying proper authentication on your application.
for more information go here http://msdn.microsoft.com/en-us/library/532aee0e(VS.71).aspx[^]
Upvotes: 1
Reputation: 3253
You could try redirecting:
function logout(){
$this->session->sess_destroy();
redirect('controller/method');
}
Upvotes: 0
Reputation: 3170
I think this could help you, it works for me.
CodeIgniter Framework version:
$this->output->set_header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT');
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0',false);
$this->output->set_header('Pragma: no-cache');
PHP version:
header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0',false);
header('Pragma: no-cache');
if you are using PHP OOP put the above code in your constructor to initialize on your pages.
Upvotes: 1