Php 在codeigniter中销毁会话时出错

Php 在codeigniter中销毁会话时出错,php,Php,我在php中使用code igniter销毁会话时遇到问题。我使用了给定的代码: 控制器:home.php public function logout() { $this->load->library('session'); $this->session->sess_destroy(); $this->session->set_flashdata('msg','Please login to continue'); redir

我在php中使用code igniter销毁会话时遇到问题。我使用了给定的代码: 控制器:home.php

public function logout()
{
    $this->load->library('session');
    $this->session->sess_destroy();
    $this->session->set_flashdata('msg','Please login to continue');
    redirect(base_url().'home/index','refresh');
}
在视图中:profile.php

<a href="<?php  echo base_url();?>home/logout">Logout</a>


一旦我在“注销”中单击,页面将重定向到“主页/索引”页面,如controller home.php中的注销功能所述。但当我在浏览器中单击后退按钮时,页面将指向配置文件页面(用户登录时加载的页面)。请建议我答案,如何销毁该会话以及为什么我的flashdata也无法工作。

您可以尝试类似的方法

function logout(){

         $this->CI =& get_instance();   
         $this->CI->session->sess_destroy();
         $msg= $this->session->set_flashdata('msg','Please login to continue');
         $data = array();

         //...

         $data['msg'] = $error;
         $this->load->view('someview',$data);
         redirect(base_url().'home/index','refresh');
}



// And in your view file

<?php if($msg) : ?>
<div id="msg_text"><?php echo $msg; ?></div>
<?php endif; ?>
函数注销(){
$this->CI=&get_instance();
$this->CI->session->sess_destroy();
$msg=$this->session->set_flashdata('msg','Please login to continue');
$data=array();
//...
$data['msg']=$error;
$this->load->view('someview',$data);
重定向(base_url().'home/index','refresh');
}
//在您的视图文件中

我认为您需要一个前导斜杠,因为
base\u url
不包含尾随斜杠-
尾随斜杠不是问题,因为函数logout()被调用,页面被重定向到“home/index”。您在破坏会话后试图设置flashdata。读取上的“销毁会话”-此函数应该是最后调用的函数,甚至flash变量也将不再可用