doudi1979 2014-04-09 16:12
浏览 30
已采纳

在同一个函数中销毁和创建会话

in my logout function i like to destroy all session except one here is my function :

    public function out(){

    $ref = $this->session->userdata('ref'); 
    var_dump($ref);

    $this->session->sess_destroy();

    $this->session->set_userdata('ref', $ref ); 


    $ref = $this->session->userdata('ref'); 
    echo '---------------------------------------<br />';
    var_dump($ref);


    }

but this doesnt work and it destroys all the session even ref and when i check ref in the next page i get null

inn the function page i get this output :

array (size=2)
  'val' => int 666
  'date' => int 1397060477

---------------------------------------

array (size=2)
  'val' => int 666
  'date' => int 1397060477

A PHP Error was encountered

Severity: Notice

Message: Undefined index: last_activity

Filename: drivers/Session_cookie.php

Line Number: 590

Backtrace:

A PHP Error was encountered

Severity: Notice

Message: Undefined index: session_id

Filename: drivers/Session_cookie.php

Line Number: 611

Backtrace: 

im using 3.0-dev

  • 写回答

4条回答 默认 最新

  • dtv995719 2014-04-09 16:23
    关注

    Try this:

    public function out(){
    
        $ref = $this->session->userdata('ref'); 
        $this->session->sess_destroy(); // this kills the ID/cookie
    
        $this->session->sess_create(); // properly start a new session with new ID/cookie
    
        if($ref)        
        $this->session->set_userdata('ref', $ref ); 
    
         redirect(base_url().'index');  
    
    }
    

    Note:

    sess_create() is not documented here: CodeIgniter Sessions

    You have to look at /system/libraries/Session.php to find sess_create()

    UPDATE

    When using Dev 3.0 then you need to do this:

    $this->session->__construct();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题