leulae Posted January 11, 2010 Share Posted January 11, 2010 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 https://forums.phpfreaks.com/topic/188018-count-session-and-trigger-events/ Share on other sites More sharing options...
oni-kun Posted January 11, 2010 Share Posted January 11, 2010 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 https://forums.phpfreaks.com/topic/188018-count-session-and-trigger-events/#findComment-992634 Share on other sites More sharing options...
leulae Posted January 12, 2010 Author Share Posted January 12, 2010 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 https://forums.phpfreaks.com/topic/188018-count-session-and-trigger-events/#findComment-993317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.