Back to vBulletin 3 Articles

Adding Currently Active Users to your own vB page
by Lynne 06 Aug 2008
Rating: (3 votes - 5.00 average)

Adding Currently Active Users to your own vB page

I've seen a few users asking about how to add the list of Currently Active Users to their own vB page. Below I document the lines of code you must add after creating your own page using one of these articles - How to create your own vBulletin-powered page! (uses vB templates) or [How-To] vBulletin API Basics: Creating Custom Pages & Misc. This article only documents what to add to a working page in order to get your Currently Active Users. You should make sure your page is working first before adding this code. I'll refer to your working page as test.php and the template in your working page as 'TEST'.

Instructions

Open your working php page and ADD the maxloggedin template to the specialtemplates array (your maxloggedin users will get reset all the time if you don't add this - I learned that the hard way!):
PHP Code:
// get special data templates from the datastore
$specialtemplates = array(
    
'maxloggedin',
); 
ADD the forumhome_loggedinuser template to the globaltemplates array so it looks like this:
PHP Code:
// pre-cache templates used by all actions
$globaltemplates = array(
    
'TEST',
    
'forumhome_loggedinuser',
); 
Then ADD the functions_bigthree.php to the required files list so it looks like this:
PHP Code:
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(
DIR '/includes/functions_bigthree.php'); 
If you are creating this page outside of your normal vb forums directory, you should change directories prior to requiring these files. It would then look like this:
PHP Code:
// ######################### REQUIRE BACK-END ############################
chdir ('/path/to/your/forums');
require_once(
'./global.php');
require_once(
DIR '/includes/functions_bigthree.php'); 
Then open your index.php page and COPY the code between the following START and
END lines. Paste these lines into the main part of your page. (You might want to copy this code from a default index.php if you have modified your index.php page.)

START with:
PHP Code:
// ### LOGGED IN USERS #################################################
$activeusers '';
if ((
$vbulletin->options['displayloggedin'] == OR $vbulletin->options['displayloggedin'] == OR ($vbulletin->options['displayloggedin'] > AND $vbulletin->userinfo['userid'])) AND !$show['search_engine'])

END with:
PHP Code:
    $show['loggedinusers'] = true;
}
else
{
    
$show['loggedinusers'] = false;

Open your template that you made (TEST) and ADD the following code in the table. Make sure it is it's own new table row.
HTML Code:
<!-- logged-in users -->
<tbody>
    <tr>
        <td class="thead" colspan="2">
            <a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_activeusers')"><img id="collapseimg_forumhome_activeusers" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_activeusers].gif" alt="" border="0" /></a>
            <a href="online.php$session[sessionurl_q]" rel="nofollow">$vbphrase[currently_active_users]</a>: $totalonline (<phrase 1="$numberregistered" 2="$numberguest">$vbphrase[x_members_and_y_guests]</phrase>)
        </td>
    </tr>
</tbody>
<tbody id="collapseobj_forumhome_activeusers" style="$vbcollapse[collapseobj_forumhome_activeusers]">
    <tr>
        <td class="alt2"><a href="online.php$session[sessionurl_q]" rel="nofollow"><img src="$stylevar[imgdir_misc]/whos_online.gif" alt="$vbphrase[view_whos_online]" border="0" /></a></td>
        <td class="alt1" width="100%">
            <div class="smallfont">
                <div style="white-space: nowrap"><phrase 1="$recordusers" 2="$recorddate" 3="$recordtime">$vbphrase[most_users_ever_online_was_x_y_at_z]</phrase></div>
                <div>$activeusers</div>
            </div>
        </td>
    </tr>
</tbody>
<!-- end logged-in users -->
Also, very important if you want your page to validate correctly!, change the other columns to span 2 columns. ie.
HTML Code:
<tr>
    <td class="tcat" colspan="2">Title</td>
</tr>
<tr>
    <td class="alt1" colspan="2">Text</td>
</tr>
That should do it! I tested this on my 3.6.8 board and on my 3.7.0 board.

vblts.ru supports vBulletin®, 2022-2024