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   View files Documentation   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum (4)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 60%Total: 1,052 All time: 3,513 This week: 113Up
Version License PHP version Categories
online 1.0.3GNU General Publi...5PHP 5, User Management


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: 341 Up9 in Indonesia Indonesia Up
Innovation award
Innovation award
Nominee: 1x



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();


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

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


  • 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  
File Role Description
Plain text file online.php Class online class
Accessible without login Plain text file Doc. Read Me Documentation

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:3,513
This week:113Up
User Ratings User Comments (1)
 All time
Very useful, thanks.
5 years ago (Octavio Leon)