Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    17

    Unanswered: How to track how many users are online in the site?

    Hello all,

    i am developing one site in which i have to track how many users are online in the site.

    just u may find link as "Who's Online".
    how to get that data?

    plese rply ASAP, its urgent.

    kindly waiting

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    PHP Code:
    <?php
    session_save_path
    ('/some/path/with/correct/permissions');

    /* Start the session */
    session_start();

    /* Define how long the maximum amount of time the session can be inactive. */
    define("MAX_IDLE_TIME"3);

    function 
    getOnlineUsers(){

         if ( 
    $directory_handle opendirsession_save_path() ) ) {
              
    $count 0;
              while ( 
    false !== ( $file readdir$directory_handle ) ) ) {
                   if(
    $file != '.' && $file != '..'){
                        
    // Comment the 'if(...){' and '}' lines if you get a significant amount of traffic
                        
    if(time()- fileatime(session_save_path() . '/' $file) < MAX_IDLE_TIME 60) {
                             
    $count++;
                        }
                   }
              }
              
    closedir($directory_handle);

              return 
    $count;

         } else {
              return 
    false;
         }     

    }

    echo 
    'Number of online users: ' getOnlineUsers() . '<br />';
    ?>
    Forget where I got that from, but it works pretty well if you don't want to use a database to track users online.

  3. #3
    Join Date
    Jan 2004
    Posts
    17
    Thankx dude for kind help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •