【问题标题】:what is the Best way to logout from page in codeigniter?从codeigniter中的页面注销的最佳方法是什么?
【发布时间】:2014-03-20 14:09:29
【问题描述】:

我在我的视图页面中创建了一个注销链接。当我点击它时,它会转到另一个页面,但是当我点击浏览器的后退按钮时,它会回到我注销的最后一页。我应该怎么做防止这种行为?
控制者:

function logout(){
$this->session->sess_destroy();
redirect('acontrol/index');}

感谢您的帮助。

【问题讨论】:

    标签: codeigniter session


    【解决方案1】:

    您可以检查before the function calls是否有一个会话。如果会话为空,则需要重新重定向到登录页面。最好您可以在__construct功能中检查您的课程。它将在您的函数调用之前调用,因此,对于每个页面,只要您的会话为空,该页面就会被重定向到登录。

    function __construct() {
       if($this->session->userdata('iUserId') == '') {
           // Redirect to Login page
           redirect('controllername/login');
       } 
    }
    

    【讨论】:

      【解决方案2】:

      您可以将会话签入控制器构造方法

      public function __construct()
          {
              // Initialization of class
              parent::__construct();
      
              if(!$this->session->userdata('id')){
      
                  $this->session->set_flashdata('error', 'Please login first');
      
                  /* if user is not login then
                  redirect back to login page and show error
                  */
      
                  redirect('admin/login/index');
              } 
      
          }
      

      【讨论】:

        猜你喜欢
        • 2011-07-08
        • 2012-02-21
        • 2015-08-08
        • 1970-01-01
        • 2020-05-23
        • 1970-01-01
        • 1970-01-01
        • 2013-06-02
        • 1970-01-01
        相关资源
        最近更新 更多