Gaurav
Gaurav

Reputation: 1972

Extracting data from cakephp 3 sessions table

I am using Database Sessions in my CakePHP 3 application as I wish to display list online employees(users) in the admin panel of the site.

I want to retrieve the logged in employee(user)s' session info (at least user id) so that their details can be displayed in the list. data column of the sessions table contains session info but I don't know how to extract specific info from it. I want Auth info from it. It contains serialized data concatenated with session key somehow.

Data Sample

Config|a:1:{s:4:"time";i:1457067440;}Flash|a:1:{s:4:"auth";a:1:{i:0;a:4:{s:7:"message";s:52:"Woopsie, you are not authorized to access that area.";s:3:"key";s:4:"auth";s:7:"element";s:13:"Flash/default";s:6:"params";a:1:{s:5:"class";s:5:"error";}}}}registrar_id|i:2;registrar_name|s:10:"Gaurav Makhecha";unread_site_updates_ids|s:1:"1";

Can anyone please guide me on how I can achieve this the best way.

Upvotes: 0

Views: 371

Answers (1)

Eber Freitas Dias
Eber Freitas Dias

Reputation: 879

I don't know if the session db is the best place to implement that feature. Maybe you could use something else...

Just thinking out loud, maybe a logged in user could, at every request, renew some kind of flag. That could be done as well every X minutes with JS. That way, you filter out "old" flags and display fresh ones, which should display active users in the moment.

There are probably better ways to do that, but I think that using the session db wouldn't be the best way.

Upvotes: 0

Related Questions