mr_mind Posted December 13, 2007 Share Posted December 13, 2007 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(); ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2007 Share Posted December 13, 2007 You already have an active thread for this, don't create a new thread for the same problem, in fact if you solved your problem you need to mark the active thread as solved. This is actually the third thread on the same code. Quote Link to comment Share on other sites More sharing options...
mr_mind Posted December 13, 2007 Author Share Posted December 13, 2007 This inst a problem it is the fix and i am about to close the other threads sorry Quote Link to comment Share on other sites More sharing options...
steveangelis Posted May 12, 2009 Share Posted May 12, 2009 I know this is old, but I am getting 10 when i run it off of my computer and530 when i run it from my server. Would anyone know why? Also how can this be modified for cookies instead of sessions? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.