Tutorialsplane

Codeigniter session example

Codeigniter session example

For using codeigniter session you need to load session library . If it already loaded in autoload.php ingore loading again.

Codeigniter Load Session Library

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

There are two ways to create session in codeigniter.

First : Using associative array

Codeigniter Set Session


$newsessdata = array(
                   'username'  => 'john',
                   'email'     => 'john@gmail.com'
               );

$this->session->set_userdata($newsessdata);

Second : Individual variable

Codeigniter Set Session


$this->session->set_userdata('some_variable_name', 'some_value');