Jump to content

Sessions Checking and counting


nezbo

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.