dousuiguang9328 2013-09-26 19:28
浏览 24

Codeigniter - 注销链接不起作用 - 会话和cookie未被破坏

i made a simple logout url with the controller and it looks like this:

 class Auth extends MX_Controller{
        function logout(){
          $this->session->sess_destroy();
          $this->bootstrap->unsetUserCookie();

          redirect(base_url(),'',301);
        }
    }

then

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'=>''
        ));
  }
}

i'm using the session DB these are the config params i'm using:

$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;

then i created a simple session library and don't know if this can block anything but i guess no cause i receive no errors at all:

<?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/ */

?>

the url is so simple,it just had to delete session and cookies, but the session and the cookies seems not to be deleted cause after launching the logout url i'm still logged.

Any clue please?

  • 写回答

2条回答 默认 最新

  • douwendu2460 2013-09-27 00:23
    关注

    you code is fasle :

    class Auth extends MX_Controller{
            function logout(){
              $this->session->sess_destroy();
              $this->bootstrap->unsetUserCookie();
    
              redirect(base_url(),'',301);
            }
        }
    

    this extends is MY_Controller,

    class Auth extends MY_Controller{
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有没有可以帮我搞一个微信建群链接,包括群名称和群资料群头像那种,不会让你白忙
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题