CodeIgniter Sessions Variables

CodeIgniter uses it’s own sessions variables, so you won’t be working with native PHP sessions and functions. Below are how to set and get session variables, as well as display all the session variables for debugging.

Set a session variable ‘user_id’ with a value of 41:

$this->session->set_userdata('user_id', 41);


Get a session variable ‘user_id’ and display it:

echo $this->session->userdata('user_id');


Display the entire session classes to see all set session variables:

print_r( $this->session->all_userdata() );


And finally, get ride of the session variable:

Scroll to Top