CodeIgniter Session


Question

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.

1
2
6/30/2009 1:14:34 PM

Accepted Answer

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

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

Then you should be able to use:

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

Does this get you what you need?

6
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'     => 'johndoe@some-site.com',
                   'logged_in' => TRUE
               );

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

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