0

I would like to make a list of all logged in users accessible through the backend. The routes are created. It is only the request to retrieve the users that I would need. Is this data in the 'sessions' table? Thank you in advance for your help

4
  • 1
    Isn't that what the View "Who's online block" is doing out-of-the-box? It would be no problem to add a page display and customize it for the backend.
    – 4k4
    Aug 7 '20 at 9:02
  • Not quite. it creates a list of the last accesses and I would like the users connected at the moment I click.
    – sensitd
    Aug 7 '20 at 9:21
  • Yes, you can search the session table for active users. Also, user type views provide a filter (current) to filter out users who are currently active.
    – Shrikant D
    Aug 7 '20 at 9:28
  • What do you mean by "connected"? The view is listing users having accessed the site in the last 15 min (you can change this).
    – 4k4
    Aug 7 '20 at 16:30
1

You can try

// 3600s is one hour.
$uids = Drupal::database()->query('SELECT uid FROM sessions WHERE uid != 0 AND `timestamp` >=:time',[':time'=>(Drupal::time()->getCurrentTime()-3600)])->fetchCol();
1
  • It seems to work as I hoped. Thanks
    – sensitd
    Aug 7 '20 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.