PHP Classes

PHP Session Count Online Users: Get the number of users that are online in a site

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 60%Total: 1,055 All time: 3,511 This week: 47Up
Version License PHP version Categories
online 1.0.3GNU General Publi...5PHP 5, User Management
Description 

Author

This class can get the number of users that are online in a site.

It can traverse the directory where PHP saves user session data to find the currently active sessions.

The class returns the number of users that have accessed the current site for the last 3 seconds.

Innovation Award
PHP Programming Innovation award nominee
October 2018
Number 2
Many PHP applications use sessions to keep track about the users that access a site.

This class provides a means to count the number of active users on a site by accessing session tracking files and counting the active sessions based on the last time a session file for an user was modified.

Manuel Lemos
Picture of John S.
Name: John S. <contact>
Classes: 1 package by
Country: Indonesia Indonesia
Age: ???
All time rank: 230334 in Indonesia Indonesia
Week rank: 180 Up4 in Indonesia Indonesia Up
Innovation award
Innovation award
Nominee: 1x

Documentation

About

Every online counter need a database, This class will not use a database, SQL or NoSQL or even flat-file. It will use PHP session file located in php.ini session.save_path or session_save_path();

Usage

require_once 'online.php';
echo online::who();

It will return integer of total number of online users from last IDLE TIME ago.

Tip

  • To change IDLE TIME you can set `MAX_IDLE_TIME` to your preferred interval
  • In order to get more accurate number, you need to edit at least one of session key value pair in every page visit
  • In shared hosting environment, `session.save_path` need to be changed, do not use default path, because it returns a count of all sessions on the server for all sites

  Files folder image Files (2)  
File Role Description
Plain text file online.php Class online class
Accessible without login Plain text file readme.md Doc. Read Me Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,055
This week:0
All time:3,511
This week:47Up
User Ratings User Comments (1)
 All time
Utility:90%StarStarStarStarStar
Consistency:84%StarStarStarStarStar
Documentation:71%StarStarStarStar
Examples:-
Tests:-
Videos:-
Overall:60%StarStarStarStar
Rank:1102
 
Very useful, thanks.
5 years ago (Octavio Leon)
70%StarStarStarStar