CodeIgniter Session


I am trying to use a third party script and extract the logged in users userid. I am aware the CodeIgniter uses some sort of encrypted sessions. Can you please suggest how to get the userid. A simple $_SESSION does not seem to work.

I am basically running a separate script and i just want the session details i.e. the userid. But I do not want to modify this script as MVC model. I want to modify it as minimal as possible.

Sorry I am very new to CodeIgniter. Thank you for your time.

6/30/2009 1:14:34 PM

Accepted Answer

Depending if you auto-load the session library or not, we will need to include:


Then you should be able to use:

$session_id = $this->session->userdata('SessionID');

Does this get you what you need?

6/30/2009 12:47:24 PM

Code Igniter session

If you want to set a session variable, for example:

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

or use the array. It's quite easy if you read the docs. And the docs in Code Igniter are great!

$newdata = array(
                   'username'  => 'johndoe',
                   'email'     => '',
                   'logged_in' => TRUE


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow