doujionggan9570 2015-06-04 09:36
浏览 29
已采纳

无法在codeigniter中更改会话值[重复]

This question already has an answer here:

I use the session in codeigniter, it works well but I can't change the value. I use this function :

$this->session->set_userdata('check', 0);

I must change the value of 'check' to 0.

Why can't ?

My question is, why i can't change the value session ? And I set the value like this for the first time :

$sess_array = array(
        'userid' => $row->userid,
        'pseudo' => $row->pseudo,
        'check'  => $row->check
);  
$this->session->set_userdata('logged_in', $sess_array);
</div>
  • 写回答

2条回答 默认 最新

  • duanpoqiu0919 2015-06-04 09:52
    关注
    $sess_array = array(
        'userid' => $row->userid,
        'pseudo' => $row->pseudo,
        'check'  => $row->check
    ); 
    // you have set session key 'logged_in' 
    $this->session->set_userdata('logged_in', $sess_array);
    
    // Get session value from existing key
    $arrSession = $this->session->userdata('logged_in');
    $arrSession['check'] = 0;
    $this->session->set_userdata('logged_in', $arrSession);
    

    You need to update value as shown above.

    If you wish to set 'check' value as you indicated. you need to do as following

    $sess_array = array(
        'userid' => $row->userid,
        'pseudo' => $row->pseudo,
        'check'  => $row->check
    ); 
    // Note that no key specified. 
    $this->session->set_userdata($sess_array);
    // Now i think you can set check value. Give it a try. Let me know which works.
    $this->session->set_userdata('check',0);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?