Back button to disable after logging out

I put below codeigniter code for controller and view. When a user logs out, the return button should not go to the previous page. But in my case, it moves to the previous page. Help me solve the problem.

Input for controller:

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>
+1
source share
3 answers

I think it can 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 use PHP OOP, enter the above code into your constructor on your pages.

+1
source

(, , ), , . , .

http://msdn.microsoft.com/en-us/library/532aee0e (VS.71).aspx [^]

+1

You can try redirecting:

function logout(){
    $this->session->sess_destroy();
    redirect('controller/method');
}
0
source

Source: https://habr.com/ru/post/1535909/


All Articles