PDA

View Full Version : total visitors online plugin not working


Chadi
07-31-2014, 07:03 PM
I have a strange issue here.

I'm using this active plugin with global_start hook location for both desktop and mobile templates. It works fine in mobile (navbar), but not in desktop (header template)

Same exact code in plugin, same code in templates:

// get online users
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];
$guestsarry = $db->query_first("SELECT COUNT(host) AS sessions FROM " . TABLE_PREFIX . "session WHERE userid = 0 AND lastactivity > $datecut");
$membersarry = $db->query_read("SELECT DISTINCT userid FROM " . TABLE_PREFIX . "session WHERE userid <> 0 AND lastactivity > $datecut");
$msxguests = intval($guestsarry['sessions']);
$msxmembers = intval($db->num_rows($membersarry));
$msxtotal = $msxmembers + $msxguests;
vB_Template::preRegister('navbar_link',array('msxt otal' => $msxtotal, 'msxmembers' => $msxmembers, 'msxguests' => $msxguests));
// get online users<div style="background-color: #fff; text-align: center; padding: 10px; float: right">
<span style="font-size: 16px; color: #777">there are <span style="color: #43A6DF; font-weight: bold">{vb:raw $msxtotal}</span> people online</span>
</div>The issue is on desktop, it is not outputting the actual number. It only says "there are members online". In mobile, it shows actual total people online, perfectly reflecting the same in the who's online footer section on the desktop version.

I have the code in the header template in desktop version and navbar template in mobile.

Scanu
07-31-2014, 07:09 PM
You'll have to register the variable also to the header template then. Try this code

// get online users
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];
$guestsarry = $db->query_first("SELECT COUNT(host) AS sessions FROM " . TABLE_PREFIX . "session WHERE userid = 0 AND lastactivity > $datecut");
$membersarry = $db->query_read("SELECT DISTINCT userid FROM " . TABLE_PREFIX . "session WHERE userid <> 0 AND lastactivity > $datecut");
$msxguests = intval($guestsarry['sessions']);
$msxmembers = intval($db->num_rows($membersarry));
$msxtotal = $msxmembers + $msxguests;
vB_Template::preRegister('navbar_link',array('msxt otal' => $msxtotal, 'msxmembers' => $msxmembers, 'msxguests' => $msxguests));
vB_Template::preRegister('header',array('msxtotal' => $msxtotal, 'msxmembers' => $msxmembers, 'msxguests' => $msxguests));
// get online users

Chadi
07-31-2014, 07:11 PM
Perfect that works! Thanks :)

Scanu
07-31-2014, 07:19 PM
You're welcome :)