0

In the below codeigniter code i have placed the controller Now when i logout and click the back button it moves to webpages .But it should not allow the user to view the page after logout by clicking back button.So anyone help to solve the issue:

Controller:login

<?php

class Login extends CI_Controller {

    function index()
    {
        $data['main_content'] = 'login_form';

        $this->load->view('includes/template', $data);      
    }
    function inactive()
    {
    echo"<script>alert('In active user Please contact the administrator');</script>";
    $this->load->view('login_form'); 
    }
    function invalid()
    {
    echo"<script>alert('Invalid username or password');</script>";
    $this->load->view('login_form'); 
    }
    function validate_credentials()
    {       
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();

        if($query) // if the user's credentials validated...
        {
            $data = array(
                'username' => $this->input->post('username'),
                'is_logged_in' => true
            );
            if($query->num_rows()>0){
             $status = $query->row()->account_status;}
            else {
             $status = ''; }
             //Account active
            if($status == 'active')
            {
               $this->session->set_userdata($data);
               redirect('site1/members_area');
            }
            else  if ($status == 'inactive')//Account In active
            {  $this->inactive();
              }
              else // incorrect username or password
        {
            $this->invalid();
        }
        }

    }   

    function signup()
    {
        $data['main_content'] = 'signup_form';
        $this->load->view('includes/template', $data);
    }

    function create_member()
    {
        $this->load->library('form_validation');

        // field name, error message, validation rules
        $this->form_validation->set_rules('first_name', 'Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
        $this->form_validation->set_rules('college_name', 'college_name', 'trim|required');
        $this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email');
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
        $this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]');
         $this->load->helper('date');

        if($this->form_validation->run() == FALSE)
        {
            $this->load->view('signup_form');
        }

        else
        {           
            $this->load->model('membership_model');

            if($query = $this->membership_model->create_member())
            {
                $data['main_content'] = 'signup_successful';
                $this->load->view('includes/template', $data);
            }
            else
            {
                $this->load->view('signup_form');           
            }
        }

    }

    function logout()
    {
        $this->session->sess_destroy();
        $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");
        $this->index();
    }

}
user2991258
  • 129
  • 1
  • 5
  • 11
  • i want not to view page after logout – user2991258 Nov 19 '13 at 05:38
  • 1
    http://stackoverflow.com/questions/10418964/codeigniter-back-button-after-logout http://stackoverflow.com/questions/13099805/clear-cache-on-back-press-to-prevent-going-back-on-login-page-or-previous-page-a http://stackoverflow.com/questions/11745368/php-codeigniter-is-showing-the-cache-when-i-press-the-back-button-after-i-logout anything helps? – Nabin Kunwar Nov 19 '13 at 05:53

1 Answers1

0

I think the following should help you out

1) Create a logout.php file and add the following code to it

<html>
 <head>
  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$( "#submit" ).trigger( "click" );
});
</script>
</head>

<body>
<form action="<?php echo base_url();?>login" method="post">
<input type="submit" id="submit" style="display: none;">
</form>
</body>
</html>

2) Modify your logout function to load a above view file logout.php

Amit Horakeri
  • 747
  • 5
  • 18