Checking which users are currently online

Hello!

Iā€™m looking or the aid of a Whoā€™s online scripts. Is that possible with Kirby? Displays which users are online now?

Thanks for help :relaxed:

I think the most simple solution would be to save the online status of each user in the User object, as an additional ā€œis_onlineā€ field or something similar. Then you could just filter all users by this field using $users->filterBy('is_online', 'online'). The only negative thing might be the need to update the user object each time someone logs in/out. This could be achieved with the userā€™s update function.

1 Like

Thanks!

Can I add $users->filterBy into the footer?

When I to this, than I became a error:

Fatal error: Call to a member function filterBy() on a non-object in ā€¦

You have to define $users first with $site->users(): http://getkirby.com/docs/cheatsheet/site/users

Okay $user->filterBy(ā€˜is_onlineā€™, ā€˜onlineā€™) work.

But I canā€™t see any online Userā€¦

Do you update your user information on login/logout to set the is_online field as @jakobploens suggested?

Yes I have this doā€¦

So what does $users->filterBy('is_online', 'online') return if a user is currently logged in?

I all Userā€™s there are onlineā€¦?

So what is the problem? I donā€™t quite understand whatā€™s missing.

  1. when user logs in
  • add is_online via controller
  1. while user is logged
  • filter users by is_online
  1. when user logs out
  • remove is_online via controller

I think I get the idea (Iā€™ll have to try it).
But kirby logs out the user automatically from time to time (not sure about the interval).

You can change the interval from your Kirby configuration.

1 Like