Jump to content

Count Session and Trigger Events


leulae

Recommended Posts

I am New in PHP, seeking a method to count logged users by counting the sessions or any …, is there any way to do it without using a database, and also eager to know a method to make to throw an event before and after session expired.

 

Thanks in advance

 

How can you record the amount of users with no database? Lets say you store a session for each user that logs in, there's no way to correlate how many users there are purely based on them. You can, however use a hack method.

 <?php
session_start();

function getUsersOnline() {
   $count = 0;

   $handle = opendir(session_save_path());
   if ($handle == false) return -1;

   while (($file = readdir($handle)) != false) {
       if (preg_match("/^sess/", $file)) $count++;
   }
   closedir($handle);

   return $count;
}
?> 

 

That is , however theorietical code. I'm sure there's other ways you can store the user count in, such as a flatfile (usercount.txt). As for your session expiry, there's not a method to singulate a user after the session has already ended. (without any further details on what you're exactly doing)

I need to restrict one user to  create only one session, I want this to restrict uses to log in to system from different places using same user ID and password. Finding a way to implement such a system without database, if I Use database how I decide user logged off when session expired

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.