Using last logged in time does not work. Your sessions can last several days / weeks, so you wonβt know the number of active users in this way.
One solution would be to create a table with login sessions in which you store this session identifier in a session cookie. Session cookies terminate as soon as the user closes his browser window so that he gives you a fairly accurate estimate of when users are logged in. If you really want to keep the entire duration of the session, you will also have to update the table with each to save the time the user last used it. It will be a little harder for your database, of course.
Wolph source share