Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Pages: [1] 2

Author Topic: Counting Guests  (Read 10449 times)

hormoSapi [hS]

  • Newbie
  • *
  • Karma: 3
  • Posts: 21
Counting Guests
« 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
Logged

Joost

  • Guest
Re: Counting Guests
« Reply #1 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.
Logged

hormoSapi [hS]

  • Newbie
  • *
  • Karma: 3
  • Posts: 21
Re: Counting Guests
« Reply #2 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
Logged

Joost

  • Guest
Re: Counting Guests
« Reply #3 on: September 11, 2007, 12:08:52 PM »

Oops :-[ Missed the minus sign!. You are right.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Counting Guests
« Reply #4 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)
« Last Edit: September 12, 2007, 02:38:13 AM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

hormoSapi [hS]

  • Newbie
  • *
  • Karma: 3
  • Posts: 21
Re: Counting Guests
« Reply #5 on: September 13, 2007, 03:53:22 AM »

Should be fine! Thanks!

hS
Logged

hormoSapi [hS]

  • Newbie
  • *
  • Karma: 3
  • Posts: 21
Re: Counting Guests
« Reply #6 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

Logged

hormoSapi [hS]

  • Newbie
  • *
  • Karma: 3
  • Posts: 21
Re: Counting Guests
« Reply #7 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

Logged

hormoSapi [hS]

  • Newbie
  • *
  • Karma: 3
  • Posts: 21
Re: Counting Guests
« Reply #8 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.
Logged

hormoSapi [hS]

  • Newbie
  • *
  • Karma: 3
  • Posts: 21
Re: Counting Guests
« Reply #9 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
Logged

adamos

  • Newbie
  • *
  • Karma: 0
  • Posts: 43
Re: Counting Guests
« Reply #10 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.
Logged

hormoSapi [hS]

  • Newbie
  • *
  • Karma: 3
  • Posts: 21
Re: Counting Guests
« Reply #11 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/ 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

Logged

adamos

  • Newbie
  • *
  • Karma: 0
  • Posts: 43
Re: Counting Guests
« Reply #12 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
« Last Edit: December 25, 2007, 08:27:44 PM by adamos »
Logged

hormoSapi [hS]

  • Newbie
  • *
  • Karma: 3
  • Posts: 21
Re: Counting Guests
« Reply #13 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.

Logged

feiming

  • Newbie
  • *
  • Karma: 0
  • Posts: 4
    • My sNews Mods
Re: Counting Guests
« Reply #14 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
« Last Edit: May 27, 2008, 05:52:23 PM by feiming »
Logged
Pages: [1] 2