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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.