php codeigniter 中的 session_destroy()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32053187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:46:14  来源:igfitidea点击:

session_destroy() in codeigniter

phpcodeigniter

提问by Zoe

How come destroy_session() method doesn't work.

为什么 destroy_session() 方法不起作用。

After set_session(), destroy_session(), I still can read_session().

在set_session()、destroy_session()之后,我仍然可以read_session()。

function set_session() {
    $this->load->library('session');
    $this->session->set_userdata('id', 4);
}

function destroy_session() {
    session_start(); 
    session_destroy();
    unset($_SESSION);
    session_regenerate_id(true);
}

function read_session() {
    $this->load->library('session');

    $id = $this->session->userdata('id');

    echo $id;
}

回答by Hasan Tareque

The Codeigniter session class does not utilize native PHP sessions. It generates its own session data, offering more flexibility for developers.

Codeigniter 会话类不使用原生 PHP 会话。它生成自己的会话数据,为开发人员提供更大的灵活性。

to unset a session variable:

取消设置会话变量:

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

to destroy the whole session:

销毁整个会话:

$this->session->sess_destroy();

hope this helps. ref: codeigniter doc

希望这可以帮助。参考:codeigniter 文档