petenaylor Posted June 30, 2011 Share Posted June 30, 2011 Hi all I have a site whereby people login to their accounts and each time they do it enters this into the session: $_SESSION['wmmadmin_email'] = "".$user_login.""; I now need to count each of these session variables and show a total on my site? How do I count them and show a total? Many thanks Pete Quote Link to comment https://forums.phpfreaks.com/topic/240785-count-total-session-values/ Share on other sites More sharing options...
Adam Posted June 30, 2011 Share Posted June 30, 2011 You mean count how many sessions there are? That's not so simple, as when your code executes you only have access to that specific user's session within the $_SESSION array. Session data by default is stored within individual files within a directory on the server, so counting the files is very inefficient. Since you have users, I'm assuming you also have a users database table to validate their username/password? Extend this table by adding a new column that stores a timestamp of their last activity (last page request). Using this timestamp you can then query for users that have been active in the last 5 minutes or so, and efficiently get an accurate count of active users. Quote Link to comment https://forums.phpfreaks.com/topic/240785-count-total-session-values/#findComment-1236746 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.