Faisad M Ali
Faisad M Ali

Reputation: 51

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
)

Upvotes: 5

Views: 3205

Answers (1)

Alex Tartan
Alex Tartan

Reputation: 6836

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()

Upvotes: 10

Related Questions