• View our reviews on Hot Scripts
  • JS Tutorial

Recent Comments

Powered by Disqus

Back to articles

Display users online without database

How to display users online without storing sessions in database? Simple, just count how many session files there are in session folder. No database required. Just change session path if you are on a shred hosting (you don't want to display all users from all websites) and call this simple function:

//change sessions path if you are on a shared hosting
ini_set('session.gc_probability', 1);

//start session

function getOnlineUsers()
    $count = 0; 
    $d = dir(session_save_path()) or die("Wrong path.");
    while (false !== ($entry = $d->read())) 
        if($entry != '.' && $entry != '..')
    return $count;  

//then call this function
$users_online = getOnlineUsers();
echo $users_online;

You may also be interested in:

Powered by

blog comments powered by Disqus