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
-
1Isn'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.– 4uk4Commented Aug 7, 2020 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.– sensitdCommented Aug 7, 2020 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 DCommented Aug 7, 2020 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).– 4uk4Commented Aug 7, 2020 at 16:30
Add a comment
|
1 Answer
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();