The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
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. |
#4
|
|||
|
|||
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. |
#5
|
|||
|
|||
WOW that's so freakin awesome of you, thank you.
What does create a new plugin using hook location misc_start mean? |
#6
|
|||
|
|||
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. |
#7
|
|||
|
|||
Dude you seriously rock, I wish I could add more 'thanks' or rep or something. Thank you so much man.
|
#8
|
||||
|
||||
So Awesome!
You dont know how long I have been looking for this. Thank you so much :up: |
#9
|
||||
|
||||
how can i display online users ( username ) in non vb pages?
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|