Track Users Online with Sessions?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Barkster

    Track Users Online with Sessions?

    Since I'm on the topic of sesions, I've seen a few examples of tracking
    online users using a mysql table and inserting the session and
    timestamp and checking it at period to remove it from the list after
    expiration time but is there a simpler way? Is there a way to count
    how many active sessions there are open at one time? I don't care to
    see user info but would like to at least know how many people are
    online. I guess getting logged in users and guests would require using
    a table or something. Is there any information on how to do this?
    Thanks

  • Barkster

    #2
    Re: Track Users Online with Sessions?

    I found this and is what I'm looking for but no matter what I get '0'
    for the count every time.

    /* Start the session */
    session_start() ;

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

    function getOnlineUsers( ){

    if ( $directory_hand le = opendir( session_save_pa th() ) ) {
    $count = 0;
    while ( false !== ( $file = readdir( $directory_hand le ) ) ) {
    if($file != '.' && $file != '..'){
    // Comment the 'if(...){' and '}' lines if you get a significant amount
    of traffic
    if(time()- fileatime(sessi on_save_path() . '\\' . $file) <
    MAX_IDLE_TIME * 60) {
    $count++;
    }
    }
    closedir($direc tory_handle);

    return $count;

    } else {
    return false;
    }

    }

    echo 'Number of online users: ' . getOnlineUsers( ) . '<br />';

    Comment

    Working...