How to detect if a user is logged in symfony?

1.1k Views Asked by At

I need to know how I can get if a specific user in symfony is logged in the application, is there a way to get the session id for the current users logged?

I've tried with a table when I have a field named is_online and y set it when the user loggin and logout on the application, so I get a problem when a user close the brower or when the session end, so the field is_online stay true. That is the reason for that I need another way to get if an user is logged on the application.

Any advice will be useful.

2

There are 2 best solutions below

0
On

Create a database field like lastonlinetstamp and a ping method in ajax which calls a service with the same session every minute. Then let the ping service update the lastonlinetstamp. If this value is older than 1 minute you know the user is offline. But: This will increase the number of requests to your server.

5
On

You can send ajax request from users and as soon as someone doesn't send request for example 1 min change his status to offline. Will be good idea to store statuses in some key-value storage i.e MemCache. Look here for details.