Checking which users are currently online


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


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():

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