PHP Classes


Recommend this page to a friend!
  Classes of John S.   PHP Session Count Online Users   Download  
Role: Documentation
Content type: text/markdown
Description: Read Me Documentation
Class: PHP Session Count Online Users
Get the number of users that are online in a site
Author: By
Last change: fix markdown
Date: 5 years ago
Size: 754 bytes


Class file image Download


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