Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to get the session_id in codeigniter 3.0

I am using

$session= $this->session->userdata();
print_r($session);

I get the below

Array
(
   [__ci_last_regenerate] => 1439379995
)
like image 289
Faisad M Ali Avatar asked Aug 12 '15 12:08

Faisad M Ali


1 Answers

According to the Docs

Accessing session metadata In previous CodeIgniter versions, the session data array included 4 items by default: ‘session_id’, ‘ip_address’, ‘user_agent’, ‘last_activity’.

This was due to the specifics of how sessions worked, but is now no longer necessary with our new implementation. However, it may happen that your application relied on these values, so here are alternative methods of accessing them:

session_id: session_id()
ip_address: $_SERVER['REMOTE_ADDR']
user_agent: $this->input->user_agent() (unused by sessions)
last_activity: Depends on the storage, no straightforward way. Sorry!

So, to get the session_id, just call session_id()

like image 170
Alex Tartan Avatar answered Nov 03 '22 02:11

Alex Tartan