简体   繁体   中英

how to count online users in pyrocms?

There is a table default_ci_sessions in pyrocms. I think this has to be done using this table. The fields of this table are:

1   session_id  varchar(40)
2   ip_address  varchar(16)
3   user_agent  varchar(120)
4   last_activity   int(10)
5   user_data   text    

sample row:

1   70bb123786d01c0be696e98cb1f6622e
2   0.0.0.0
3   Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19
4   1336371726
5   a:7:{s:9:"user_data";s:0:"";s:8:"username";s:5:"admin";s:5:"email";s:22:"abc@gmail.com";s:2:"id";s:1:"1";s:7:"user_id";s:1:"1";s:8:"group_id";s:1:"1";s:5:"group";s:5:"admin";}

I am developing on my localhost and there is just one (above) user registered. What I was thinking before I see the content of the table was that there should be one record at that table since you know :). But there are already 120 records there including guest users session_ids and 10 rows for my user (admin). I think the only way is to figure out what can I do with this last_activity field.

And an offtopic question : why there are so much sessions there? aren't they active sessions? So can I group them all for each username and pick the biggest last_activity ?

You can consider a user logged in (since You have no information about logging out) with last activity not older than 24 minutes (24 mins is the time browser default holds the session).

So in Your query You will count those records from default_ci_sessions where last_activity >= NOW() - INTERVAL '24' MINUTES ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM