vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How to display total number of users online outside VB? (https://vborg.vbsupport.ru/showthread.php?t=276560)

microdot 01-07-2012 04:18 AM

How to display total number of users online outside VB?
 
Hey all,

Does anyone know how I can display the number of current users online on non-vb pages?

Many thanks for your help

kh99 01-07-2012 04:12 PM

You mean the number of users who are viewing your vb pages, but displayed on a non-vb page, or the number of users viewing any page? If it's the second one, I don't know how you'd do that - it depends on how the non-vb pages are created. But for the number of vb users - if your non-vb pages are php scripts, you could include the vb global.php and then maybe use vb functions, or you might be able to read the session table from the database. If your non-vb pages are static html, you could write a "vb powered" php script that returned the info, then call it from a javascript function in your html.

microdot 01-08-2012 07:58 AM

Thanks man.

Yep, it's pulling the current number of users from vb and displaying it on a wordpress page.

Don't have much of a clue about php... been trying to get my head round it for years.

kh99 01-08-2012 05:09 PM

OK, I tried to simplify the code from index.php since you only want the counts, but I'm not sure I got it all right (it does say 1 registered and 0 guests when I try it on my test site, so it looks good). Anyway, create a new plugin using hook location misc_start and this code:

Code:

if ($_REQUEST['do'] == 'vbusers')
{
  $datecut = TIMENOW - $vbulletin->options['cookietimeout'];
  $numberregistered = 0;
  $numberguest = 0;

  $forumusers = $vbulletin->db->query_read_slave("
        SELECT userid FROM " . TABLE_PREFIX . "session AS session
                WHERE session.lastactivity > $datecut
        ");
  while ($loggedin = $vbulletin->db->fetch_array($forumusers))
  {
      $userid = $loggedin['userid'];
      if (!$userid)
        $numberguest++;
      else
        $numberregistered++;
  }
  unset($loggedin);
  $vbulletin->db->free_result($forumusers);

  echo "var number_registered = $numberregistered;\n";
  echo "var number_guests = $numberguest;\n";
  exit;
}


Then in the page where you want to display it, put something like this:

Code:

<script src="http://my-site.com/forums/misc.php?do=vbusers" type="text/javascript"></script>
<script type="text/javascript">
<!--
document.writeln(number_registered + " registered users<br />");
document.writeln(number_guests + " guests<br />");
document.writeln((number_guests + number_registered) + " total vb user(s)<br />");
//-->
</script>


of course you need to change the url (in red) to your site, and you can change the html in the writeln lines to be whatever you want.

microdot 01-09-2012 12:31 PM

WOW that's so freakin awesome of you, thank you.

What does create a new plugin using hook location misc_start mean?

kh99 01-09-2012 12:37 PM

Go to the adminCP, and under Plugins & Products (on the left) click on Add New Plugin. Select the hook location from the drop-down menu and paste the code in the large text area. Enter a title (something so that months or years from now you'll remember what this is for), then click the "Yes" radio button to enable the plugin, and Save. You can leave the other fields at their default values.

If it causes a problem and you want to disable or delete it, you can use the Plugin Manager.

microdot 01-10-2012 09:36 AM

Dude you seriously rock, I wish I could add more 'thanks' or rep or something. Thank you so much man.

digitalelise 01-16-2013 03:38 PM

So Awesome!

You dont know how long I have been looking for this.

Thank you so much :up:

mohammad6006 09-11-2013 02:29 PM

how can i display online users ( username ) in non vb pages?


All times are GMT. The time now is 01:57 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.01028 seconds
  • Memory Usage 1,728KB
  • 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
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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