doupu0619 2013-10-29 07:48
浏览 34

CodeIgniter - 单击后退按钮后退出后仍可访问该成员的页面

I am using CodeIgniter.

After I logon to the member's and click logout, I could still view the member's page when I click the BACK button.

Question Does anyone know so that if the user has logged out, it could not access the Member's page even clicking of BACK button?

Please see my code below..

Thanks..

    class Site extends CI_Controller{

    function index()
    {   
        if(!isset($this->session->userdata['is_loggged_in'])) 
            $this->login(); 
        else 
            $this->_template();      
    }

    function login()
    { 
        $data['main_content'] = 'login_form';
        $data['page_title']   = 'Login - php';
        $this->load->view('include/template' , $data);  
    }

    function validate()
    {  
        $this->load->library('form_validation'); 
        $this->form_validation->set_rules('username' , 'Username' , 'trim|required' );
        $this->form_validation->set_rules('password' , 'Password' , 'trim|required' ); 

        if($this->form_validation->run() == FALSE)
        {
            $this->login();
        } 
        else
        { 
            $this->load->model('member_model' , 'member');
            $query = $this->member->checklogin(); 

            //login successful , make sure no duplicate entry during registration
            if($query->num_rows() == 1)
            {
                $data = array(
                    'is_loggged_in' => TRUE ,
                    'username'      => $this->input->post('username'), 
                );
                $this->session->set_userdata($data);
                $this->_template();
            }
            else
            { 
                $data = array(
                        'main_content' => 'login_form' ,
                        'page_title'   => 'Error login' ,
                        'page_error'   => 'Invalid Username or password. '

                );
                $this->load->view('include/template' , $data); 
            }

        }
    }

    function _template()
    { 
        $data = array(
            'main_content' => 'include/default_inc',
            'page_title'   => 'Welcome home ran'
        ); 

        $this->load->view('include/template' , $data);  
    }

    function logout()
    { 
        $this->session->sess_destroy();
        redirect('site/login');
        exit;
    }
  }

/* end of controller site */
  • 写回答

5条回答 默认 最新

  • doushifang4382 2013-10-29 08:06
    关注

    instead of checking session in index function try checking it in constructor

    function __constuctor()
    {   
        parent::__construct();
        $session = $this->session->userdata('is_loggged_in');
        if ( !$session) {
            $this->login(); 
        }else{
            $this->_template();    
        }     
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号