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)

slip 03-19-2001 12:52 AM

Okay.. I want to be able to show on an external page (outside of vbulletin) the number of total regged users, and the number of online users..

This code was workign PERFECTLY with vB114 but it produces an error with vb2..

heres the code..
Code:

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

$loggedins=mysql_query("SELECT COUNT(sessionid) AS sessions FROM session",$db);
$tempa=mysql_fetch_array($loggedins);
$totalonline=$tempa[sessions];

$registered=mysql_query("SELECT COUNT(userid) AS registered FROM user",$db);
$tempb=mysql_fetch_array($registered);
$regged=$tempb[registered];

echo "<font face=arial size=2>
We have a total of $regged registered users.  There are currently $totalonline users online at the moment.</font>
";
?>

and now heres what it shows with vb 20 installed..

"Warning: 0 is not a MySQL result index in /home/redg/htdocs/online2.php on line 7
We have a total of 3130 registered users. There are currently users online at the moment. "



any ideas are greatly appreciated..
slip

03-19-2001 01:33 AM

Code:

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

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

$users=mysql_query("SELECT COUNT(userid) AS registeredusers FROM user",$db) or die ("double oops");
while($user = mysql_fetch_array($users))
        $totalusers=number_format($user[registeredusers]);

echo "<font face=arial size=2>
We have a total of $totalusers registered users.  There are currently $totalonline users online at the moment.</font>
";
?>

should do it...

[edited to correct invalid query]

03-19-2001 01:49 AM

i did that, and i only get "oops" now when i go to that file.. any ideas?

03-19-2001 02:00 AM

Yeah... I just checked the session table and there is no such field as 'sessionid'.

Replace your first query with this:
Code:

"SELECT COUNT(userid) AS users FROM session"

03-19-2001 02:10 AM

woo hoo!
you seriously rule!!! :D :D :D

thanks!

03-19-2001 10:55 PM

is there a way to put this into a html page?

03-20-2001 12:43 AM

Quote:

Originally posted by Blue2000
is there a way to put this into a html page?
Do you mean an HTML page as in a page with a .html extension? If so, then no, unless your server has been configured to parse HTML files as PHP.

03-20-2001 01:17 AM

ahh, but there is ;)

SSI from the .php file

03-20-2001 01:26 AM

Quote:

Originally posted by Flare945
ahh, but there is ;)
Oh, okay then ;)

03-20-2001 12:19 PM

The results in VBulletin 2.0 are different to the results in your script. It counts correctly the sessions, but why shows the vbulletin other results? Any suggestions?

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.

03-21-2001 02:28 AM

Thanks For Your Help

But can you post the whole code?
I didnt understand your directions!
Thanks

03-21-2001 03:59 AM

Sorry, I changed the code but it shows me 0members and 0 visitors!

;)

You are on the right way, but there should be one mistake...

03-21-2001 05:40 AM

Couldnt get it to work either

03-21-2001 11:16 AM

Hmm. I noticed the 0 people yesterday, with different settings.

Just tried out:
I just changed "$datecut = time()-$cookietimeout;" into "$datecut = time()-300;"

And that worked. It just means it shows who's online in the last 5 minutes...

Can it be that the $cookietimeout query doesn't return a number but plain text?

03-21-2001 11:57 AM

This works. I have the timeout settings on 500 seconds in the vbulletin board, so the working skript looks now like that: (remember the right path to the admin/config file!)

Code:

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

$datecut = time()-500;

$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]);

$users=mysql_query("SELECT COUNT(userid) AS registeredusers FROM user",$db) or die ("double oops");
while($user = mysql_fetch_array($users))
        $totalusers=number_format($user[registeredusers]);


echo "<font face=arial size=2>
We have a total of $totalusers registered users. There are currently $membersonline members and $guestsonline guests online.</font>
";
?>


03-21-2001 12:06 PM

Hey Peter, I tried your exact code,
and it listed 3 members online,

But the thing is.... it'sa test board and I only have 2 members total!

I don't think it works.

Can anyone make this actually list the members name like in the index.php file?

03-21-2001 12:47 PM

hmm, thats right, something is more wrong, i have nearly the right results like in the vbulletib forum, but only nearly, so i thought at the beginning, the code is right. Sorry, I was to fast ;)

03-21-2001 07:12 PM

Quote:

Originally posted by Pingu
I just changed "$datecut = time()-$cookietimeout;" into "$datecut = time()-300;"
And that worked. It just means it shows who's online in the last 5 minutes...
Can it be that the $cookietimeout query doesn't return a number but plain text?
I made a mistake in the code and therefore it was getting a MySQL error back instead of the cookietimeout. The corrected code is below.

Quote:

Originally posted by Sarge
...and it listed 3 members online, but the thing is.... it'sa test board and I only have 2 members total!
I think I figured this out too - adding "DISTINCT" should fix it. See the corrected code below.

OK after a bit of scratching my head, I think I have this thing figured out.

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[value];

$loggedins=mysql_query("SELECT DISTINCT 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]);

$users=mysql_query("SELECT COUNT(userid) AS registeredusers FROM user",$db) or die ("double oops");
while($user = mysql_fetch_array($users))
        $totalusers=number_format($user[registeredusers]);

echo "<font face=arial size=2>We have a total of $totalusers registered users. There are currently $membersonline members and $guestsonline guests online.</font>";
?>

Just remember to change the path to config.php, based on where you put this file. I think this should work now. *crosses fingers*

03-21-2001 07:26 PM

Now it lists 0 members and 0 guests online

03-21-2001 07:45 PM

1 Attachment(s)
OK I figured it out, finally. Change the code as follows. Replace this:
Code:

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

with this:
Code:

$cookievalue = mysql_query("SELECT value FROM setting WHERE varname = 'cookietimeout'");
$cookietimeout = mysql_result($cookievalue, 0, 0);
$datecut = time()-$cookietimeout;

I've also attached the complete code in a file. Unzip the file online.php from it, and then open that file in Notepad (Windows) or Simpletext (Mac) and edit the path to config.php, if necessary. Upload it to where you want and then include it using PHP
Code:

<? include("/path/to/online.php"); ?>
or SSI
Code:

<!--#include virtual="/path/to/online.php"-->
.

Problems? Let me know. It should work now. :)

03-21-2001 08:05 PM

Works Like A Charm!
Thanks!

03-21-2001 08:12 PM

I'll work on getting to show the user names. Give me a few hours, and I'll release it in a new thread. :)

03-21-2001 08:15 PM

AWESOME!
Can't Wait Bro!

03-21-2001 08:29 PM

You rock, it worked great!
I couldn't get all of the code from the attachment though.

03-21-2001 08:32 PM

Jyaki: What do you mean? I just tried downloading it and it worked fine...?

03-21-2001 08:37 PM

When I click on it, This is everything I get:
Code:

$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]); $users=mysql_query("SELECT COUNT(userid) AS registeredusers FROM user",$db) or die ("double oops"); while($user = mysql_fetch_array($users)) $totalusers=number_format($user[registeredusers]); echo "We have a total of $totalusers registered users. There are currently $membersonline members and $guestsonline guests online."; ?>

03-21-2001 08:40 PM

I've changed it to a zip file. Let me know if you're still having problems.

03-21-2001 08:43 PM

I just copied your earlier code and made the changes you specified manually.
I've been wanting this one for a long time.
Thanks

03-21-2001 10:43 PM

As promised, I released the online users with user names. There's a link in my sig. Enjoy! :D


All times are GMT. The time now is 02:33 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.01933 seconds
  • Memory Usage 1,819KB
  • 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
  • (13)bbcode_code_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (39)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete