我在codeigniter中使用会话,它运行良好,但我无法更改值。 我用这个函数:
$this->session->set_userdata('check', 0);
我必须将'check'的值更改为0。
为什么不能?
我的问题是,为什么我无法更改价值会话?我第一次设置这样的值:
$sess_array = array(
'userid' => $row->userid,
'pseudo' => $row->pseudo,
'check' => $row->check
);
$this->session->set_userdata('logged_in', $sess_array);
答案 0 :(得分:1)
您可以尝试取消设置值,然后为其指定一个新值,类似下面的代码:
$check= $this->session->userdata('check');
if(!empty($check)){
$this->session->unset_userdata('check');
$this->session->set_userdata('check', 0);
}
echo $this->session->userdata('check');
如果有效,请告诉我!!
答案 1 :(得分:1)
$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);
您需要更新值,如上所示。
如果您希望按照指示设置“检查”值。你需要做如下
$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);