views:

463

answers:

4

What is the best way to get the current visitors session id in Kohana v3? session_id() doesn't seem to work and only returns null for me..

At the moment Im using cookie::get('session'), but that doesn't work on the first time you access the site, which I need to do.

I know you could do $this->session->id() in Kohana v2, but that doesn't seem to exist in KO3...

Thanks

A: 

From looking at the source on GitHub, I can't seem to find a method for returning the id.

However, session_id() is used for the native driver, so perhaps it should work in your case.

Perhaps if you call session_regenerate_id() first?

alex
+2  A: 

Typically you use any of these 3 session type: Native, Cookie, Database.

For cookie, I believe you don't have session id. Even if you call Session::instance()->regenerate() when using cookie as session type, it will only return NULL.

For native, you should be able to get the ID when generating it by Session::instance()->regenerate() which returns the session id.

For database, Session_Database has protected $_session_id where session id is stored. You may want to extend that class and write your own getter.

Hope that helps.

SyaZ
A: 

If you're using the database driver then the cookie will hold the session id.

On the other hand it seems to be no direct way to get the session id. As how @SyaZ suggested, you should extend the session class and write your own getter method.

feketegy