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:
<?php //change sessions path if you are on a shared hosting session_save_path('/path/to/your/sessions'); ini_set('session.gc_probability', 1); //start session session_start(); function getOnlineUsers() { $count = 0; $d = dir(session_save_path()) or die("Wrong path."); while (false !== ($entry = $d->read())) { if($entry != '.' && $entry != '..') { $count++; } } $d->close(); return $count; } //then call this function $users_online = getOnlineUsers(); echo $users_online; ?>
You may also be interested in:
Powered by BlogAlike.com










