首页 文章

CodeIgniter Session不会破坏

提问于
浏览
0

我有登录功能,然后有一个数组来显示会话数据但是当我点击退出时,它会重定向到登录页面,但如果我手动加载成员页面,则不会清除会话数据 .

控制器功能

public function logout(){

        $this->session->sess_destroy();
        redirect('site/login');
    }
public function members(){
        
        if ($this->session->userdata('is_logged_in')){
        $data['title'] = "Members";
        $this->load->view('view_header');
        $this->load->view("view_members", $data); 
        }
        else{
            redirect('site/restricted');
        }

    }

模型

class Model_users extends CI_Model {
    
    
    public function canLogin(){
        
        $this->db->where('Username', $this->input->post('Username'));
        $this->db->where('Password', md5($this->input->post('Password')));
        
        $query = $this->db->get('user_registration');
        
        
        if ($query->num_rows() == 1){
            return true;
        }
        else{
            return false;
        }
        
    }
      
    
}

会员观点

<?php
	
	echo "<pre>";
	print_r ($this->session->all_userdata());
	echo "</pre>";
	
	?>
	
	<a href='<?php echo base_url()."index.php/site/logout"?>'>Logout</a>

由于注销功能运行,我不知道我在这里缺少什么,但似乎没有清除会话 .

1 回答

  • 1

    尝试在Home控制器中创建一个清除缓存的功能,如下所示:

    function clear_cache()
    {
        $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");
    }
    

    所以从控制器的构造函数中调用它

    class Home extends CI_Controller
    {
        function __construct()
        {
            parent:: __construct();
            $this->clear_cache();
        }
    }
    

    希望它有所帮助 .

相关问题