Welcome Guest, Not a member yet? Register   Sign In
Count Total Logged-in and Anonymous Users
#1

[eluser]kyko[/eluser]
Hello Fellow CI programmers,

I am developing a membership site that needs to display the site stats just like what we have in the bottom of this forum. I tried tracking logged in users through tagging them from a DB and when they logged out the normal way, toggles them off. This works pretty fine until such time that the user leaves the application by closing the browser leaving it status as if the user is still logged in. Another question is how to keep track of anonymous users?

any idea guys?
#2

[eluser]Gewa[/eluser]
i think you should play with session timeout time...or javascript with pinging each 10sec...
#3

[eluser]Sumon[/eluser]
From my point of view, maintain a database table to store currently logged in users along with last activity time. And for every refresh of your site, find out those users who's activity time is greater then 15 minute and delete it immediately.

On the other hand, for currently logged in users, update activity time with current time.

Finally, all members of this table are currently logged in members. So display them in your preferred format Smile
#4

[eluser]manilodisan[/eluser]
Similar tu Sumon, we're using a field in the user's table where we store the unix timestamp of the last activity time (whenever they refresh or change a page that field gets updated). Showing the logged in members would be a simple query where you get them by a time limit you set, let's say, 10 mins:

Code:
SELECT * FROM users_table WHERE last_seen > ' . now () - ( 600 ) . '


You will obviously need the date helper loaded.
#5

[eluser]kyko[/eluser]
Thanks for the suggestions guys,

What i did was to implement a DB Sessions. In that way, i can track all users that are logged in (that is if session data is not NULL) and users that are guests (that is if session data is null). I have also implemented the tip from Sumon, that in every page refresh, i have to check whether the last activity exceeds the allowable idle time. All sessions that exceeds the predefined time will be deleted. If, however, the user is logged in, the last_activity should be updated during page refresh.

Again, thanks for all your suggestions.




Theme © iAndrew 2016 - Forum software by © MyBB