Users Online

« Back :: Tagged with Drupal :: Drupal 6.x :: Functions :: PHP :: Snippets ::

 A function that shows online users either anonymous, authenticated, or both.

 /**
  * Returns number of users online
  *
  * @param $type
  *  can be 'anon', 'auth', or '' which returns both
  */
 function deuxcode_users_online($type = '') {
 
   $interval = time() - variable_get('user_block_seconds_online', 900);
 
   switch ($type) {
     case 'anon':
       $users_count = sess_count($interval);
       break;
     case 'auth':
       $users_count = db_result(db_query("SELECT COUNT(DISTINCT uid) FROM {sessions} WHERE uid > 0 AND timestamp >= %d", $interval));
       break;
     default:
       $count_anon = sess_count($interval);
       $count_auth = db_result(db_query("SELECT COUNT(DISTINCT uid) FROM {sessions} WHERE uid > 0 AND timestamp >= %d", $interval));
       $users_count = $count_anon + $count_auth;
        break;
   }
   return $users_count;
 }

 

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <blockquote> <blockcode> <pre> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Copyright © 2010 deuxcode.com
Powered by Drupal. Valid XHTML 1.0 Strict and CSS 2.1.