Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

session_destroy() in codeigniter

How come destroy_session() method doesn't work.

After set_session(), destroy_session(), I still can 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;
}
like image 663
Zoe Avatar asked Dec 03 '25 18:12

Zoe


1 Answers

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

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

like image 146
Hasan Tareque Avatar answered Dec 06 '25 07:12

Hasan Tareque