nezbo Posted March 9, 2009 Share Posted March 9, 2009 Hi all Is there a simple way to count the number of sessions and get there values... eg if there are number of users logged on i want to track who is on line, ie $numberOfUsers = count($_session['user']); then i want to get the session. i am testing it on 2 computers useing difrent session_ID's. I am going to try my best and make the session name "user" unique and not just user once i have it working. Link to comment https://forums.phpfreaks.com/topic/148601-sessions-checking-and-counting/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 9, 2009 Share Posted March 9, 2009 A session is just a container. The session data files are only deleted when session garbage collection runs. Session garbage collection runs randomly using session.gc_probability and session.gc_divisor and only when a session_start() is executed. So, counting sessions is not an accurate indicator of the number of logged in members are on line. The normal way of displaying a count of active logged in members is to insert/update the username/last access time in a database table (or a flat file database) on each page visit. Then to display the number (or the usernames) of active logged in members, you query the table for records that are newer than a limit you pick (5, 10, 20... minutes.) P.S. You can also insert/update where on your site each member is at (last requested URL) and display that information as well. Link to comment https://forums.phpfreaks.com/topic/148601-sessions-checking-and-counting/#findComment-780362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.