views:

1130

answers:

3

Hello,

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.

+3  A: 

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?

Rob Lund
but which file should i include?
Alec Smart
i am using a separate file i.e. say abc.php which is outside the framework and everything. but i want the $session_id. So which file to include?
Alec Smart
Are you traveling from a CI page to a non-CI page? If you are, I would pass the session_id explicitly as a post parm. Another option might be to drop a cookie with the session id while inside CI, and then pick it up on the non-CI page. I hope I am not completely missing the point of your question.
Rob Lund
A: 

well i have a similar problem, i want to create session so that no one else can view administrator pages..so please help.... the code above will work i think but just tell me is this to be used in controller?

:) sorry for being idiot.. I'm new to CI

bluepicaso
A: 

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'     => '[email protected]',
                   'logged_in' => TRUE
               );

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