autoload.php
present in the filepath applicatio/config in Controller constructor by adding the below code.
[php]$autoload['libraries'] = array('session');[/php]
Note: Normally, CodeIgniter Session class won't use default PHP sessions because session class creates its own session data. set_userdata()
. Every user data can be added individually or can be grouped into an associative array.
[php]$this->session->set_userdata($array); // $array is an associative array of your new data[/php]
Session data can read and retrieve the data using the method userdata()
with array index as the value.
[php]$this->session->userdata('item'); // Where item is the array index like session id[/php]
All the data of the session can be retrieved using the method all_userdata()
[php]$this->session->all_userdata() // Read all session values[/php]
All the session data can be removed using the method unset_userdata
.
[php]$this->session->unset_userdata('some_name'); // Removing values from session[/php]
The method sess_destory() will completely destroy the session in the application.
[php]$this->session->sess_destroy();[/php]