我用控制器做了一个简单的注销 url,它看起来像这样:
class Auth extends MX_Controller{
function logout(){
$this->session->sess_destroy();
$this->bootstrap->unsetUserCookie();
redirect(base_url(),'',301);
}
}
然后
class Bootstrap{
function unsetUserCookie(){
$CI =& get_instance();
$CI->input->set_cookie(
array(
'name'=>'remember_me',
'value'=>'',
'expire'=>''
));
$CI->input->set_cookie(
array(
'name'=>'remember_me_n',
'value'=>'',
'expire'=>''
));
$CI->input->set_cookie(
array(
'name'=>'duser_lang',
'value'=>'',
'expire'=>''
));
$CI->input->set_cookie(
array(
'name'=>'duser_country',
'value'=>'',
'expire'=>''
));
}
}
我正在使用会话数据库这些是我正在使用的配置参数:
$config['sess_cookie_name'] = 'sess_id';
$config['sess_expiration'] = 0; //24hours -> 8640
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_session';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 3000000000;
然后我创建了一个简单的会话库,不知道这是否会阻止任何东西,但我想没有因为我根本没有收到错误:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*We encode/decode all session data in base64 to avoid problems with multybityes data*/
class MY_Session extends CI_Session {
function set_userdata($data, $singleVar = NULL) {
if(is_array($data)){
$newValues = array();
foreach ($data as $key=>$value) {
$newValues[$key] = base64_encode($value);
}
parent::set_userdata($newValues);
}
else{
if(is_array($singleVar)){
$newValues = array();
foreach ($singleVar as $key=>$value) {
$newValues[$key] = base64_encode($value);
}
//Encode $singleVar
parent::set_userdata($data, $newValues);
}else{
parent::set_userdata($data, base64_encode($singleVar));
}
}
}
function set_flashdata($data, $singleVar = NULL) {
if(is_array($data)){
$newValues = array();
foreach ($data as $key=>$value) {
$newValues[$key] = base64_encode($value);
}
parent::set_flashdata($newValues);
}
else{
if(is_array($singleVar)){
$newValues = array();
foreach ($singleVar as $key=>$value) {
$newValues[$key] = base64_encode($value);
}
//Encode $singleVar
parent::set_flashdata($data, $newValues);
}else{
parent::set_flashdata($data, base64_encode($singleVar));
}
}
}
public function userdata($item) {
$data = parent::userdata($item);
if(is_array($data)){
$newData = array();
foreach ($data as $key => $value) {
$newData[$key] = base64_decode($value);
}
return $newData;
}else{
//Decode $data
return base64_decode($data);
}
}
}
/* End of file */
/* Location: ./application/controllers/ */
?>
url 是如此简单,它只需要删除会话和 cookie,但会话和 cookie 似乎没有被删除,因为在启动注销 url 后我仍然登录。
请问有什么线索吗?