CodeIgniter: unset all userdata, but not destroy the session

删除回忆录丶 提交于 2019-12-05 18:58:54

This is very simple!

 $this->session->unset_userdata('some_name');

or

 $array_items = array('username' => '', 'email' => '');
 $this->session->unset_userdata($array_items);

I hope this helps!

Edit: It looks like you actually don't keep track of anything in your session (kind of strange?). You could call this function I wrote up:

function unset_only() {
    $user_data = $this->session->all_userdata();

    foreach ($user_data as $key => $value) {
        if ($key != 'session_id' && $key != 'ip_address' && $key != 'user_agent' && $key != 'last_activity') {
            $this->session->unset_userdata($key);
        }
    }
}

Of course, that assumes you use the default CI session setup though.

Copied from codeigniter forum:

All it does is kills the users cookie, but the userdata will remain within the session class until the end of the current request. The session will be reinitialised on the next request, and there will be no userdata available. Basically, all it does is severs the link between the user and the server session, but the data still remains until the end of the request.

If it’s that much of an issue, you can do this:

$this->session->userdata = array();

Md.Jewel Mia

I manage it please try it .

$this->load->library('session');

// write parameter your session data

$this->session->unset_userdata('sessiondata');

// if you want to session unset group then try it

$array_items = array('username' => '', 'email' => '');

$this->session->unset_userdata($array_items);

You can try this one. In the latest version above code is not working.

$unset_array_items = array('token_id', 'last_id');
$this->session->unset_userdata($unset_array_items);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!