2

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.

j0k
  • 22,600
  • 28
  • 79
  • 90
JERC
  • 1,584
  • 3
  • 17
  • 38

2 Answers2

4

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.

Community
  • 1
  • 1
Ruben Nagoga
  • 2,178
  • 1
  • 19
  • 30
  • Thanks, this will be a solution, but by security if an application is in inactivity more than 15 minutes, the session has to close. – JERC May 24 '12 at 16:49
  • For example with an ajax request every 5 mins, the session never close. – JERC May 24 '12 at 16:56
  • I can't understand where are you going to use session for storing statuses or have I missed something? – Ruben Nagoga May 24 '12 at 16:56
  • 1
    I just want to get if an user is logged, y tell that user session_id() has close by security in 15 minutes in inactivity, with an ajax request every 5 mins, the sesion never close,and that can't be allowed. – JERC May 24 '12 at 17:09
  • 1
    you can send the ping ajax only if you detected that the user did something in the page (mouseevent or keypress, you can use a jquery plugin to do that), if the user leaves the browser open without doing anything no ping will be sent and the session will expire. I wouldn't recomend to store session data or statuses on memcache because you don't have guarantee of the persistence of the statuses store in memory. – javiertoledos May 24 '12 at 18:15
1

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.

Del Pedro
  • 1,216
  • 12
  • 32