sNews Forum

sNews 1.6 (previous version) => sNewsMU (sNews Multi User version) => MU issues/bugs => Topic started by: hormoSapi [hS] on September 11, 2007, 11:22:48 am

Title: Counting Guests
Post by: hormoSapi [hS] on September 11, 2007, 11:22:48 am
After a registered user loged in the counter "Guests online" will be decreased 

Registered users online: 2 ( admin beck )
Guests online: -1

Registered users online: 3 ( admin beck tuga )
Guests online: -2
Title: Re: Counting Guests
Post by: Joost on September 11, 2007, 11:36:23 am
Welcome hormosapi,

Looks normal to me. Before you are logged in, you are considered being a guest. After that no longer. You don't want one person to be counted twice. :)
By the way, if there seems to be a bug in a mod, report back to the thread where the mod is posted. That way, the developer of the mod will know about the problem. This section is for bugs in the standard (default) sNews.
Title: Re: Counting Guests
Post by: hormoSapi [hS] on September 11, 2007, 12:01:19 pm
Thanks for your answer.

1, I would think if Guests Online number cannot be less than 0. If i'm wrong sorry, but who count the users who are not online? Or the amount of online users wasn't increase when a new guest had came to online.

2,  I''ve just installed a 1.6 MU and i'm playing with it now, that why i posted to here. What about 1.6 MU? Is it standard or mod?

Sorry for my English, i hope i could be clear enough!

hS
Title: Re: Counting Guests
Post by: Joost on September 11, 2007, 12:08:52 pm
Oops :-[ Missed the minus sign!. You are right.
Title: Re: Counting Guests
Post by: Keyrocks on September 11, 2007, 05:20:44 pm
2,  I''ve just installed a 1.6 MU and i'm playing with it now, that why i posted to here. What about 1.6 MU? Is it standard or mod?
HS... 1.6 MU is not a "standard" issue of sNews. It is a modified package based on the default (virgin) sNews 1.6 package, crafted by Bakercad. It is best to post inquiries about bugs experienced with sNews 16 MU right here in the MU section... now that Philmoz has created it.  8)
Title: Re: Counting Guests
Post by: hormoSapi [hS] on September 13, 2007, 03:53:22 am
Should be fine! Thanks!

hS
Title: Re: Counting Guests
Post by: hormoSapi [hS] on September 13, 2007, 04:33:00 am
The bug occurs only when more users log in from same IP.

It is caused by this line:

line Num 1239: $query = "SELECT DISTINCT sess FROM ".db('prefix')."guests WHERE ip <> '$addr' AND sess <> ''";
line Num 1242: echo '<br /><span>'.l('mu_guests_online').': <strong>'.(($user +1) - $reg_user).'</strong></span>';

After altering it works well on my computer:
line Num 1239: $query = "SELECT DISTINCT sess FROM ".db('prefix')."guests WHERE sess <> ''";
line Num 1242: echo '<br /><span>'.l('mu_guests_online').': <strong>'.(($user ) - $reg_user).'</strong></span>';

Unfortunately i cannot test it from different ip and as i'm not an expert, but i don't understand why these options was need here.

regards hS

Title: Re: Counting Guests
Post by: hormoSapi [hS] on September 14, 2007, 09:16:14 am
I found an another problem it cause bad counting also.
It's turned up after i left the site without logging out. That was the user "Test". Then it fails on next day touching.

It still keeps the user logged in for 6 hours after leaving and no activities. Then if i'm coming again (with same IP) it shows me registered and logged in user, it looks like i'm recognised. But it force me to log in again. Then if i use an another user to log in, it fails the counting again.

------------------------
befor login
------------------------

Barbecued by sNews ˇ Bejelentkezés              // Barbecued by sNews ˇ Login

Regisztrált felhasználók: 1 ( Test )
Vendégek: 0
 
-------------------------
after login
-------------------------

Regisztrált felhasználók: 2 ( admin Test )          // Registered users
Vendégek: -1                                                  // Guests
Title: Re: Counting Guests
Post by: hormoSapi [hS] on September 16, 2007, 06:36:36 pm
It looks like we have to alter only 1 line, number 1242.  I was blind.

line Num 1239: $query = "SELECT DISTINCT sess FROM ".db('prefix')."guests WHERE ip <> '$addr' AND sess <> ''";
line Num 1242: echo '<br /><span>'.l('mu_guests_online').': <strong>'.(($user +1) - $reg_user).'</strong></span>';

new suggestation:
line Num 1239: $query = "SELECT DISTINCT sess FROM ".db('prefix')."guests WHERE sess <> ''";
line Num 1242: echo '<br /><span>'.l('mu_guests_online').': <strong>'.(($user)).'</strong></span>';

a quotation from an earlier comment of me:
Quote
i don't understand why these options was need here.
I have understood . And I have too apologize bramsyuur (he wrote these codeblock), because probably his intention was to count 1 IP or computer for only 1 Guest. That's right. And the question is theoretical how we count the guests. I would do by browsers. It doesn't affect others if they use only 1 browser on  1 computer.

But you can use your PDA via your computer, and i guess so that your IP is same like your computer, or different browsers's usage allow you login with different names. And  if you can  login with 2 or more usernames, in this case how many users are you?

In addition, there is an other problem what  we have to sort out. It's related with this topic and i would continue this topic with it. If  clients lost their session the users stay loggedin in the users table, but they have to log in again.

In this example all user and guests i'm from one computer but only the guests are living connections with the server. It's showing 5 users logged in, but they are not indeed.
Quote
Barbecued by sNews ˇ Login

Registered users online: 5 ( admin fank beck maki tuga )
Guests online: 4
Then if i  want to reach the admin interface under a logged in username, i have to log in at first.
Title: Re: Counting Guests
Post by: hormoSapi [hS] on September 19, 2007, 10:54:53 pm
Hopefully my version for counting online users works right. It's not tested too accurate yet. But it does not depend on IP.  It has to work right if your users come from behind a gateway or you use it from one computer but with different clients.

if you have already created your database and tables:
ALTER TABLE `guests` CHANGE `id` `uname` VARCHAR( 50 ) NOT NULL DEFAULT 'Anonym'

else:
CREATE TABLE `guests` (
`uname` varchar( 50 ) NOT NULL DEFAULT 'Anonym',
`timestamp` varchar( 50 ) NOT NULL default '',
`ip` varchar( 50 ) NOT NULL default '',
`sess` varchar( 255 ) NOT NULL default '',
) ;

change the lines in the snewsMU.php file (original position from 420 to 424):
//START [MOD] Users Online (MU) by bramsyuur
   if (s('users_online') == 'on') {
      mysql_query ("UPDATE ".db('prefix')."users SET online = 'YES' WHERE id = '".$_SESSION['id']."'");
   }
//END [MOD] Users Online (MU) by bramsyuur


//START [MOD] Users Online (MU) suggested by hormoSapi
   if (s('users_online') == 'on') {
           mysql_query ("UPDATE ".db('prefix')."users SET online = 'YES' WHERE id = '".$_SESSION['id']."'");
   }            
   $sess = session_id();            
   mysql_query ("UPDATE ".db('prefix')."guests SET uname = '$user' WHERE sess = '$sess'");
//END [MOD] Users Online (MU) suggested by hormoSapi

change the lines in the snewsMU.php file (original position from 645 to 649):
        //START [MOD] Users Online (MU) by bramsyuur
   if (s('users_online') == 'on') {
     mysql_query ("UPDATE ".db('prefix')."users SET online = 'NO' WHERE username_real = '".$_SESSION['username']."'");
   }
   //END [MOD] Users Online (MU) by bramsyuur


   //START [MOD] Users Online (MU) suggested by hormoSapi
   if (s('users_online') == 'on') {
          mysql_query ("UPDATE ".db('prefix')."users SET online = 'NO' WHERE username_real = '".$_SESSION['username']."'");
       $sess = session_id();
       mysql_query("UPDATE ".db('prefix')."guests SET uname = 'Anonym' WHERE sess = '$sess'");
       $_SESSION['username'] = 'Anonym';
   }
   //END [MOD] Users Online (MU) suggested by hormoSapi


change the lines in the snewsMU.php file (original position from 1227 to 1259):
       //START [MOD] Users Online (MU) by bramsyuur
        function users_online() {
   if (s('users_online') == 'on') {
     ## For Users
     $query = "SELECT * FROM ".db('prefix')."users WHERE online = 'YES'";
     $result = mysql_query($query);
     $reg_user = mysql_num_rows($result);
     echo '<span>'.l('mu_registered_users_online').': <strong>'.$reg_user.'</strong></span>';
     if ($reg_user > '0'){
       echo ' ( ';
        $i = 0;
        while ($r = mysql_fetch_array($result)) {
        echo '<strong>'.$r['username_real'].'</strong> ';
     }
     $i++;
     echo ' )';
   }
   ## For Guests
   $t_stamp = time();                                                                                           
   $timeout = $t_stamp - 120; // 120 = 2 minutes
   $addr = $_SERVER['REMOTE_ADDR'];
   $sess = session_id();
   $query = "INSERT INTO ".db('prefix')."guests (timestamp, ip, sess) VALUES ('$t_stamp', '$addr', '$sess')";
   mysql_query($query);
   $query = "DELETE FROM ".db('prefix')."guests WHERE timestamp < $timeout";
   mysql_query($query);
   $query = "SELECT DISTINCT sess FROM ".db('prefix')."guests WHERE ip <> '$addr' AND sess <> ''";
   $result = mysql_query($query);
   $user = mysql_num_rows($result);                                                                 
   echo '<br /><span>'.l('mu_guests_online').': <strong>'.(($user +1) - $reg_user).'</strong></span>';
   }
}
//END [MOD] Users/Guests Online (MU) by bramsyuur


        //START [MOD] Users Online (MU) suggested by hormoSapi
        function users_online() {
   if (s('users_online') == 'on') {
   
     $t_stamp = time();                                                                                           
     $timeout = $t_stamp - 120; // 120 = 2 minutes
     $addr = $_SERVER['REMOTE_ADDR'];
     $sess = session_id();
   
          $query = "DELETE FROM ".db('prefix')."guests WHERE timestamp < '$timeout' ";
     mysql_query($query);   
   
     $sname = $_SESSION['username'] != '' ? $_SESSION['username']: 'Anonym';
     $query = "INSERT INTO ".db('prefix')."guests (uname, timestamp, ip, sess) VALUES ('$sname', '$t_stamp', '$addr', '$sess')";
     mysql_query($query);   
   
     $query = "SELECT DISTINCT uname FROM ".db('prefix')."guests WHERE sess <> '' AND uname <> 'Anonym'";   
     $result = mysql_query($query);
     $ruser = mysql_num_rows($result);
     echo '<br /><span>'.'Registered users'.': <strong>'.(($ruser)).'</strong></span>'.'<br />';   
     if( $ruser > 0) {
       for( $i=0; $i < $ruser && $ruser; $i++) echo mysql_result($result, $i);
          }   
                   
          $query = "SELECT DISTINCT sess FROM ".db('prefix')."guests WHERE sess <> '' AND uname = 'Anonym'";
     $result = mysql_query($query);
     $anonyms = mysql_num_rows($result);                                                                 
     echo '<br /><span>'.l('mu_guests_online').': <strong>'.(($anonyms)).'</strong></span>';
   }
        }
        //END [MOD] Users/Guests Online (MU) suggested by hormoSapi


regards hS
Title: Re: Counting Guests
Post by: adamos on December 22, 2007, 03:31:31 am
did anyone check this yet? i didnt see any comments yet and i have this issue with counting guests.
Title: Re: Counting Guests
Post by: hormoSapi [hS] on December 24, 2007, 11:54:42 pm
I haven't got any feedback.  And I haven't got time to test it well. But you can find an instance  of it here: http://hormosapi.isgreat.org/snewsMU/ (http://hormosapi.isgreat.org/snewsMU/) and there are some test users: test01, test02, ..., test05,  passwords are same as user's names.

if you test it, then something wrong, just let me know

Title: Re: Counting Guests
Post by: adamos on December 25, 2007, 06:21:41 pm
I tested the current mod (not yours) and is not working properly.

when i open 2 browsers(IE,FF) from my desktop and login with test 01 test 02 it looks fine - it shows 2 users online and their name. but when i open my laptop and login it shows only 1 user test03 logged in. then when i refresh the pages they get mixed up. i.e it shows only test 01 or test 03 test 02.

Tomorrow i will try your mod and tell you if its working.

Adam
Title: Re: Counting Guests
Post by: hormoSapi [hS] on December 25, 2007, 11:15:02 pm
look at the next codeline: $timeout = $t_stamp - 120; // 120 = 2 minutes

Were you under that limit when you tried with your laptop? Users are counted only while they are active on the site.

All session expire after a time is limited to by the server. But, that timeout value above is only for maintain our stored data of guests in our database. You can increase that number, but don't give bigger value for it than your session expiration on your server.

Title: Re: Counting Guests
Post by: feiming on May 27, 2008, 11:37:54 am
Hi All,

I had this problem and i know why.I think it got to do with user not logout when they close the browser and when they logging again,which will cause the guest to be in negative
Title: Re: Counting Guests
Post by: hormoSapi [hS] on June 04, 2008, 10:32:42 pm
May you could get a  working solution from the topic as well.  ;)   But I have to notice it's not actualised to the last release but probably it's not to much change and you can port it easily.

hS
Title: Re: Counting Guests
Post by: pepetech on January 19, 2010, 12:06:25 am
Correction can be expected?
Title: Re: Counting Guests
Post by: alks on January 25, 2011, 12:04:19 pm
Partly related to this subject, My issue is that logged in users of some of the websites I have up and running are not always logging out - just closing the browser (despite me asking them to log out). This means that their names remains on display (sometimes for weeks) despite no longer being active - it only goes away when they log back in and then log out again. Sometime several names remain on display when non are active.
Is this how it was intended to work?

alks