Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/240785-count-total-session-values/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.