简体   繁体   English

codeigniter-注销后的返回按钮仍然有效

[英]codeigniter - back button after logout still working

created a simple page of session, Even after logout from the page i'm still able to access the login page. 创建了一个简单的会话页面,即使从该页面注销后,我仍然能够访问登录页面。 I have also destroyed all the session but still can't find any solution. 我也销毁了所有会话,但仍然找不到任何解决方案。

view - flashdata_home.php 视图-flashdata_home.php

<form action='add' method='post'>

     <input type ='text' name='value'/>
     <input type='submit' value='Enter ' />

</form>

Controller - FlashData_Controller.php 控制器-FlashData_Controller.php

<?php

class FlashData_Controller Extends CI_Controller {


    function __construct() {
        parent::__construct();

        $this->load->library('session');
        $this->load->helper('url');

    }

    public function index(){
         $this->load->view('flashdata_home');
    }

    public function add(){
    // adding flash data 
    //$this->session->set_flashdata('item','This is me');

    $this->session->set_userdata('Name',$this->input->post('value'));

    //redirect to home page
    //  redirect('flashdata');

    if($this->session->has_userdata('Name')){

        $data = array('value' => $this->session->Name);
        $this->load->view('adminflashdata_home',$data);
    }
    else
    {
        $this->load->view('flashdata_home');
    }
   }

    public function logout(){

        $this->session->unset_userdata('Name');
        $this->session->sess_destroy('Name');
        $this->load->view('flashdata_home');

    }

}

view - adminflashdata_home.php 视图-adminflashdata_home.php

<?php 
echo $value;
<li><a href="logout">Logout</a></li>
?> 

Unsettling the session in CI is very simple and it looks like this. 在CI中使会话不稳定非常简单,看起来像这样。

In your Code you have unset the data but you have to unset the variable as i did. 在您的代码中,您未设置数据,但必须像我一样取消设置变量。

For Single Data: 对于单个数据:

$this->session->unset_userdata('some_name');

For Array of Datas: 对于数据数组:

$array_items = array('username' => '', 'email' => '');
$this->session->unset_userdata($array_items);

For destroy the session: 对于销毁会话:

$this->session->sess_destroy();

I think your problem is, though we destroy session we can still access the page that should be loaded only if the user in logged in. 我认为您的问题是,尽管我们破坏了会话,但仅当用户登录后,我们仍然可以访问应该加载的页面。

For example, when user log in with correct credentials the url should look like this: localhost/app/controller/function (just for instance). 例如,当用户使用正确的凭据登录时,URL应如下所示:localhost / app / controller / function(仅作为示例)。 And later when the user log out you will redirect back to login page. 然后,当用户注销时,您将重定向回登录页面。 But if we type localhost/app/controller/function in url or if we click back button in browser, the browser will load the page !!! 但是,如果我们在url中键入localhost / app / controller / function或单击浏览器中的“后退”按钮,浏览器将加载页面! I consider your stated problem is same like this. 我认为您所说的问题是一样的。

For this problem I always use a solution in every function of controller. 对于这个问题,我总是在控制器的每个功能中都使用一个解决方案。 Like; 喜欢;

class MainController extends CI_Controller {
  function test {
    $user_name = $this->session->userdata('user_name');
    if(isset($user_name)) {
      //the actual function code goes here
    }
    else {
      //redirect to the login function
    }
  }
}

I hope this helped some one.. cheers.. 我希望这可以帮助一些人..欢呼..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM