vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Extracting Online Users from SQL Database (https://vborg.vbsupport.ru/showthread.php?t=164097)

OnyxChase 12-02-2007 04:29 AM

Extracting Online Users from SQL Database
 
I started a thread which I wanted to extract the amount of total members on the forum. This has worked wonderfully but I am now looking for a way to extract the amount of users online from the database.

I am currently using a PHP script to call up the database and retrieve the information. However I am not familliar with the table I should be using, I'm currently using the vb_session table but it is giving me a wrong number for online users.

My goal is to get the amount of users online (members and guests) on the forum. But this is going to be called from another PHP page not related to the forum.

Code:

<?php

mysql_connect('localhost', 'thedogtr_stats', 'stats911');
mysql_select_db('thedogtr_amember');

$r = mysql_query('select count(*) from vbulletin_user');
$r = mysql_fetch_array($r);
$registeredusercount = $r[0];

$r2 = mysql_query('select count(*) from vbulletin_session');
$r2 = mysql_fetch_array($r2);
$onlineusercount = $r2[0];


echo $registeredusercount[0] . ',' . $registeredusercount[1] . $registeredusercount[2] . $registeredusercount[3] . ' Registered Members<br>';
echo $onlineusercount . ' Users Online <u>Now</u>';
?>

Any help would be greatly appreciated!! Thank you!

Opserty 12-02-2007 09:12 AM

Look in the index.php file of your vBulletin site. There should be a section which is commented something like "Online Users" or "Whats going on", there is code there that you could modify slighty and just use that.

Basically this is what it does:
  1. Fetches rows from the session table that are within the cut-off time (TIMENOW - 1hr(in secs)?)
  2. Counts total vistors
  3. Checks if userid == 0, (if it does then the user is a guest, otherwise the user is member)
  4. Increments seperate counters for member and guest count.


All times are GMT. The time now is 02:36 PM.

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.00980 seconds
  • Memory Usage 1,713KB
  • 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
  • (1)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)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