Jump to content

I just had to show you this.


mr_mind

Recommended Posts

Alright i finally figured out how to show how many users are online with a simple function. The requirements are for this that you have your session save path set properly. Thats all you need and your ready to go.

 

This will allow 3 minutes of idle time on a page before the user is deemed offline. but that should not be much of a problem. the output should be something like this:

 

Users Online: 1

 

if you do not get a number then your session save path is most likely not set properly

<?php
function users_online() {
	$users_online_max_idle = 3;
	$users_online_count = 0;
	$users_online_files = glob(session_save_path() . '/*');
	foreach($users_online_files as $users_online_file) {
		if(filesize($users_online_file)>0) {
			if(date("i")-date("i", fileatime($users_online_file)) < ($users_online_max_idle * 60)) {
				$users_online_count = $users_online_count+1;
			}
		}
	}
	return 'Online Users: ' . $users_online_count;
}
print users_online();
?>

Link to comment
Share on other sites

  • 1 year later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.