vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   I *really* need help with getting this online users thing working.. (https://vborg.vbsupport.ru/showthread.php?t=11772)

03-20-2001 01:29 PM

yeah, this script "works" but it doesnt really work.

for example when i have 60 users online it says there are 120, and it keeps going up, and then every now and then it will drop down to the actual number..

any ideas..?

03-20-2001 01:47 PM

I think the online vbulletin script works with cookies and with a timeout option. The onlinescript by Slip counts all userid's in "session". So the results are different.

Compare in index.php from vbulletin:

Code:

if ($displayloggedin) {
  $datecut=time()-$cookietimeout;

  //$loggedins=$DB_site->query_first("SELECT COUNT(*) AS sessions FROM session WHERE lastactivity>$datecut");
  //$totalonline=$loggedins['sessions'];
  $loggedins=$DB_site->query_first("SELECT COUNT(*) AS sessions FROM session WHERE userid=0 AND lastactivity>$datecut");
  $numberguest=$loggedins['sessions'];
  //$numberregistered=$totalonline-$numberguest;


03-20-2001 02:30 PM

would anyone mind telling me how to implement that?

sorry, i'm incredibly stupid when it comes to PHP stuff..

03-20-2001 02:57 PM

Well, you could require() the global.php file and then you could use the $cookietimeout variable. Or you could pull it from the database yourself, either way (it's in the settings table, I believe). :) But then, you would adjust the code:
Code:

<?
require("forum/admin/config.php");
$datecut = time()-$cookietimeout;
$db=mysql_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname);

$loggedins=mysql_query("SELECT COUNT(userid) AS users FROM session WHERE lastactivity>$datecut AND userid=0",$db) or die ("oops");
while($loggedin = mysql_fetch_array($loggedins))
        $totalonline=number_format($loggedin[users]);

// rest deleted to save space, but leave it in there!
?>

I added the part in red

03-20-2001 04:20 PM

That's what I thought, and it got rid of the cumulative effect of the previous code.

But now it insists there are 0 people online :(

03-20-2001 07:11 PM

Is it possible to add the number of "guests" currently online as well?

Thanks :)
-Hideki

03-20-2001 09:37 PM

anyone want to help with fixing this?

03-20-2001 09:53 PM

I have been looking at it...give me some time..

03-20-2001 10:07 PM

It would be coool if it actually showed the members (who)that are online like index.php

03-20-2001 10:47 PM

OK I think I goofed. I looked at the sessions table, so here goes.

For registered members, you need it where userid>0. For guests, it's where userid=0. So let's revisit the code:

Code:

<?
require("forum/admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname);

$cookietimeout = mysql_query("SELECT value FROM setting WHERE varname = cookietimeout");
$datecut = time()-$cookietimeout;


$loggedins=mysql_query("SELECT COUNT(userid) AS users FROM session WHERE lastactivity>$datecut AND userid>0",$db) or die ("oops");
while($loggedin = mysql_fetch_array($loggedins))
        $membersonline=number_format($loggedin[users]);

$guestsloggedins=mysql_query("SELECT COUNT(userid) AS users FROM session WHERE lastactivity>$datecut AND userid=0",$db) or die ("oops");
while($guestsloggedin = mysql_fetch_array($guestsloggedins))
    $guestsonline=number_format($guestsloggedin[users]);


// rest of code to display numbers
?>

New code is in red. (I also changed a couple variables, but the new code is highlighted to point out what we did wrong.)
I also added a couple lines to set the date cut without involving global.php.
Use $membersonline to display the members online, and use $guestsonline to display the guests.


All times are GMT. The time now is 09:49 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01153 seconds
  • Memory Usage 1,735KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete