How would I keep track of number of current sessions on my website?
If you just want to know who's looking through pages on a little rinky-dink site, one way is to have an app-wide (or static) list of the latest requests, along with the date/time of the request. Whenever someone requests a page, remove all of the "old" hits (older than X minutes), and append (or update) the visitor's info with a date/time of now,
Note, for a really busy site, this would probably be a bad idea. A somewhat more scalable solution would be to have a 'last visit' column in your users table, and update that whenever the user requests a page. But that wouldn't be helpful to track anonymous/not-logged-in users.
Either way, to see who's "active", you go through the data and find all the visits/users with a last-visit time less than X minutes ago, where X is some number you feel is appropriate. 20-60 minutes is usually good enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With