我想銷燬會話數據,但不能這樣做。無法銷燬會話
當我點擊註銷按鈕時,它總是顯示出現一些問題,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";
}
}
}
}
}
}
你需要session_start();之前你可以銷燬它 也header(「Location ...」)正在發送標題,所以你不能關閉會話之後。做關閉會話後的重定向 – Raj
@Raj請參閱標籤codeigniter – RiggsFolly
爲什麼你會假設一個問題發生了什麼?我不知道'sess_destroy()'應該返回什麼,但是手冊沒有提到任何返回值,所以我不會測試它或者依賴它。請注意,php警告可能是由事實上,你調用該方法兩次。 – jeroen