我想破坏会话数据但不能这样做。
当我点击退出按钮时,它总是显示出现了一些问题,var_dump()的值显示为NULL。
显示消息,例如消息: session_destroy():尝试销毁未初始化的会话
控制器: Users.php
class Users extends CI_Controller
{
public function logout()
{
$result = $this->session->sess_destroy();
var_dump($result = $this->session->sess_destroy());
if($result)
{
echo "You are logged Out!!";
}
else
{
echo "Some problem has been occured";
}
}
public function login()
{
$this->form_validation->set_rules('customer-id', 'custid', 'trim|required');
if ($this->form_validation->run() == FALSE)
{
echo "Please Enter Customer ID";
}
else
{
$this->form_validation->set_rules('pass', 'password', 'trim|required');
if ($this->form_validation->run() == FALSE)
{
echo "Please Enter Password";
}
else
{
$custid = $this->input->post("customer-id");
$password = $this->__encrip_password($this->input->post('pass'));
if('loginuser' == TRUE)
{
$data = $this->user_model->get_username($custid);
//$data['custid'] = $custid;
$this->session->set_flashdata('data',$data);
$this->session->keep_flashdata('data');
var_dump($this->session->flashdata('data'));
//echo $data;
redirect('users/clientview');
//$this->load->view('clientview', $data);
}
else
{
$result = $this->user_model->login($custid, $password);
if ($result)
{
$sessiondata = array('customer-id' => $custid,
'loginuser' => TRUE);
$this->session->set_userdata($sessiondata);
$data['custid'] = $custid;
echo "You have successfully logged-in :)";
}
else
{
echo $custid;
echo $password;
echo "Invalid Username or Password";
}
}
}
}
}
}
答案 0 :(得分:4)
您正试图破坏会话TWICE。
$result = $this->session->sess_destroy();
var_dump($result = $this->session->sess_destroy());
执行此操作,因为第一行会破坏会话,第二行会抛出有关未初始化会话的错误,因为您尝试在第二行中再次销毁它。
$result = $this->session->sess_destroy();
var_dump($result);
我也不确定
sess_destroy()
是否实际上会返回任何内容供您测试?