允许在注销后查看页面

时间:2013-11-19 05:32:08

标签: php codeigniter logout

在下面的codeigniter代码中,我已经放置了控制器现在当我退出并点击后退按钮时它会移动到网页。但是它不应该允许用户通过点击后退按钮退出后查看页面。所以任何人都可以帮忙解决问题:

控制器:登录

<?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();
    }

}

1 个答案:

答案 0 :(得分:0)

我认为以下内容可以帮助你

1)创建一个logout.php文件并将以下代码添加到其中

<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)修改您的注销功能以加载上面的视图文件logout.php