How does the "Most Time Online" feature calculate time?

Started by MaxXimus, May 21, 2008, 10:53:55 am

Previous topic - Next topic

MaxXimus

Does it update every so often? I usually leave my browser windows open idleing on webpages, but my time online never seems to grow. I was just wondering how time is calculated, and the circumstances in which time is added to your count.

UglyJoe

Interesting question.  I'll poke around SMF's source code later and try to figure that out (since Google isn't helping much...).

133MHz

Apparently you have to be doing something on the forum for it to register time, not just leaving the window open doing nothing, maybe checking cookies every X seconds or something. Makes sense, otherwise I'd just leave my browser window open 24/7 and rack up online time ;D.


133MHz

At the forum main page, go down where it says Forum Stats and click on [More Stats].

JC

133 is right. You've got to be active. Once you become inactive, I think you get an extra 10-15 minutes (that's how long you'll show at the bottom of the mainpage as active. After 10-15 minutes, you disappear from the bottom of the mainpage -- no more time given until you become active again.

UglyJoe

To answer your question:


  // Mark your session as being logged.
  $_SESSION['log_time'] = time();

  // Well, they are online now.
  if (empty($_SESSION['timeOnlineUpdated']))
    $_SESSION['timeOnlineUpdated'] = time();

  // Set their login time, if not already done within the last minute.
  if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60)
  {
    // Don't count longer than 15 minutes.
    if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15)
      $_SESSION['timeOnlineUpdated'] = time();

    $user_settings['totalTimeLoggedIn'] += time() - $_SESSION['timeOnlineUpdated'];
    updateMemberData($ID_MEMBER, array('lastLogin' => time(), 'memberIP' => '\'' . $user_info['ip'] . '\'', 'memberIP2' => '\'' . $_SERVER['BAN_CHECK_IP'] .

    if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2)
      cache_put_data('user_settings-' . $ID_MEMBER, $user_settings, 60);

    $user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated'];
    $_SESSION['timeOnlineUpdated'] = time();
  }


It's basically this:

-You access the forum (and are already logged in)
---Your total time does not go up
-You then access a thread 5 minutes later
---Your total time goes up by 5 minutes
-You then access a thread 30 seconds later
---You total time does not go up (less than 60 seconds from the last time update)
-You then access a thread 45 seconds later
---Your total time goes up by 75 seconds (30 + 45 = 75 seconds, which is more than 60 seconds, which means your time goes up).
-You then access a thread 16 minutes later
---Your total time does not go up (the limit is 15 minutes between actions, at this point, you've started a new "session").
-You then access a thread 7 minutes later
---Your total time goes up by 7 minutes.

Does that clear things up?

JC


Paul-FC


MaxXimus

That is why I brought it up. You signed up after me, and you have been online almost twice as much. I just can't see how that is possible, especially since I log in about 10 to 15 times a day. :S