Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-07-2012, 04:18 AM
microdot microdot is offline
 
Join Date: May 2008
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 01-07-2012, 04:12 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Благодарность от:
microdot
  #3  
Old 01-08-2012, 07:58 AM
microdot microdot is offline
 
Join Date: May 2008
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 01-08-2012, 05:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 01-09-2012, 12:31 PM
microdot microdot is offline
 
Join Date: May 2008
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

What does create a new plugin using hook location misc_start mean?
Reply With Quote
  #6  
Old 01-09-2012, 12:37 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 01-10-2012, 09:36 AM
microdot microdot is offline
 
Join Date: May 2008
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Dude you seriously rock, I wish I could add more 'thanks' or rep or something. Thank you so much man.
Reply With Quote
  #8  
Old 01-16-2013, 03:38 PM
digitalelise's Avatar
digitalelise digitalelise is offline
 
Join Date: Nov 2012
Posts: 9
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So Awesome!

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

Thank you so much :up:
Reply With Quote
  #9  
Old 09-11-2013, 02:29 PM
mohammad6006's Avatar
mohammad6006 mohammad6006 is offline
 
Join Date: May 2008
Location: IRAN (Tabriz)
Posts: 116
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:45 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04251 seconds
  • Memory Usage 2,239KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (1)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete