XF 2.1 How do I get a session object by its id?

⭐ Alex ⭐

Well-known member
$app->session()->getSessionId(); gets a session id. How can one get a session knowing its id?

I would need something such as $app->getSession($sessionId);
 
Update: I found this:


$public_sessions = $app->container('session.public.storage');
$session = $public_sessions->getSession($sessionId);

How ever, this returns a raw array from the database, now I need a way to get the user of this session.
 
I suppose I can instantiate a new session object and use session.start($ipaddress), but it's unclear to me whether userId will get set.
 
Silly me, it was in the sessionData.

$sessionData = $public_sessions->getSession($sessionId);
$userId = $sessionData['userId'];

Well thanks for your help everyone, today I learned how to get a session by id and get some info like the user!
 
Back
Top Bottom