Using the default Zend_Auth session storage (PHP Sessions), it creates a session ID and puts it in a cookie. If I want to get at the authenticated user's username (identity), the Zend_Auth::getInstance()->getIdentity()
method gets that. However, I want to get at the user's session ID. I can get at it just by looking at $_COOKIE
, or using session_id()
but that seems hackish, and if I ever moved away from PHP Session storage might it break? So what's the best way to get the current session ID of the Zend_Auth session?
Asked
Active
Viewed 8,391 times
2

MidnightLightning
- 6,715
- 5
- 44
- 68
-
What about using a standard function for its intended purpose is hackish? – tuespetre Sep 25 '12 at 00:01
-
@tuespetre if I were creating sessions with `session_start()`, then getting the ID with `session_id()` does make sense and is not hackish. But, since I'm working with a library that may be doing other things, or may be doing other things in the future, it seems a disconnect to use a higher-level library function along with a low-level core call. – MidnightLightning Sep 25 '12 at 05:54
1 Answers
7
I don't think you're going to find a nice way to do this. If such a method existed it would be defined in Zend_Auth_Storage_Interface
, but non-session types of storage don't necessarily have a session ID equivalent so the auth storage classes don't have any abstraction for this. The closest you'll get is probably:
Zend_Session::getId()
but this just calls PHP's session_id()
, since Zend_Session
is dependent on the in-built PHP session functionality.

Tim Fountain
- 33,093
- 5
- 41
- 69