View Full Version : # Of Users Online - EXTRA FEATURES!
SystemLogic
04-21-2001, 10:58 PM
Is there anyway that I can put some sort of code on the pages of my actual site (not the message boards) so that it adds each person to the # of users online? And then put something on each page of my site:
"XXX Users Currently Online"
I think it would be pretty easy to do something like this, but if anybody can let me know, I would appreciate it a lot.
JamesUS
04-22-2001, 06:15 AM
I believe to do this all you need to do is do:
require("./forums/global.php");
And to add it to your own page just look at how it is done in index.php
SystemLogic
04-22-2001, 04:31 PM
I just tried that and it's not working.....Is it just me, or does that not work?
JamesUS
04-22-2001, 05:15 PM
What doesn't work about it?
Wayne Luke
04-22-2001, 05:19 PM
We include a pseudo-total on many of our pages at SitePoint. We do it by running a cron job every 5 minutes and putting the results into a text file. We then include that text file where ever we want the information to display. Mainly in the various active topic sections throughout the network. This text file is stored in our admin directory as is the code to generate it.
Here is the script we use:
// Now Online - copyright 2001 SitePoint Pty. Ltd. All Rights Reserved.
<?
chdir("..");
include("global.php");
chdir("admin");
$datecut=time()-$cookietimeout;
$loggedins=$DB_site->query_first("SELECT COUNT(*) AS sessions FROM session WHERE userid=0 AND lastactivity>$datecut");
$numberguest=$loggedins['sessions'];
$numbervisible=0;
$numberregistered=0;
$loggedins=$DB_site->query("SELECT DISTINCT session.userid,username,invisible
FROM session
LEFT JOIN user ON (user.userid=session.userid)
WHERE session.userid<>0 AND session.lastactivity>$datecut
ORDER BY invisible ASC, username ASC");
while ($loggedin=$DB_site->fetch_array($loggedins)) {
$numberregistered++;
}
$DB_site->free_result($loggedins);
$totalonline=$numberregistered+$numberguest;
($numberregistered > 1) ? ($membertext = "members") : ($membertext = "member");
($numberguest > 1) ? ($guesttext = "guests") : ($guesttext = "guest");
$fp = fopen ("nowonline.txt", "w");
fwrite
(
$fp,
"There are currently $numberregistered $membertext and $numberguest $guesttext on the forums.<br>"
);
fclose ($fp);
?>
Feel free to use it as long as the copyright remains.
SystemLogic
04-22-2001, 06:25 PM
wluke, thanks for that script, but that is not exactly what I was looking for, although part of it. Let me give an example.
Say you head to my site, systemlogic.net to read a review. That user is not in the forums, but I would like them to be added to the online list (so if they are not registered or logged on they are guests). So basically to add the users online functionality to the actual site. And then with that, do what you did to include the total number of users online.
This seems like it would be possible by just doing whatever kind PHP code or cookie code onto each page that I want to be included, right?
James gave you the code to do it.
I need to know how do you put a PHP code such as James of Luke's, into a .shtml file?
SystemLogic
04-22-2001, 09:30 PM
Alright well I added global.php and saw no difference. And then I tried putting some stuff from index.php in but I kept getting errors. So I have no clue what sort of PHP code to put, so if anybody that knows how to code, could you help me out?
Also, I don't think it's possible to parse PHP in a .shtml file right?
tubedogg
04-22-2001, 09:49 PM
<!--#include file="file.php"-->
That will include the file.php and parse whatever is in file.php. (you would put this in a .shtm or .shtml file).
SystemLogic
04-23-2001, 03:14 PM
Alright I put this on some pages:
<?
require("$abspath/boards/global.php");
if ($displayloggedin) {
$datecut=time()-$cookietimeout;
//$loggedins=$DB_site->query_first("SELECT COUNT(*) AS sessions FROM session WHERE lastactivity>$datecut");
//$totalonline=$loggedins['sessions'];
$loggedins=$DB_site->query_first("SELECT COUNT(*) AS sessions FROM session WHERE userid=0 AND lastactivity>$datecut");
$numberguest=$loggedins['sessions'];
//$numberregistered=$totalonline-$numberguest;
$numbervisible=0;
$numberregistered=0;
//$loggedins=$DB_site->query("SELECT DISTINCT user.userid,username FROM user,session WHERE session.userid=user.userid AND session.userid<>0 AND invisible=0 AND session.lastactivity>$datecut ORDER BY username");
$loggedins=$DB_site->query("SELECT DISTINCT session.userid,username,invisible
FROM session
LEFT JOIN user ON (user.userid=session.userid)
WHERE session.userid>0 AND session.lastactivity>$datecut
ORDER BY invisible, username");
if ($loggedin=$DB_site->fetch_array($loggedins)) {
$numberregistered++;
if ($loggedin['invisible']==0 or $bbuserinfo['usergroupid']==6) {
$numbervisible++;
$userid=$loggedin['userid'];
if ($loggedin['invisible']==1) { // Invisible User but show to Admin
$username=$loggedin['username'];
$invisibleuser = '*';
} else {
$username=$loggedin['username'];
$invisibleuser = '';
}
$location=$loggedin['location'];
eval("\$activeusers = \"".gettemplate('forumhome_loggedinuser')."\";");
}
while ($loggedin=$DB_site->fetch_array($loggedins)) {
$numberregistered++;
$invisibleuser = '';
if ($loggedin['invisible']==1 and $bbuserinfo['usergroupid']!=6) {
continue;
}
$numbervisible++;
$userid=$loggedin['userid'];
if ($loggedin['invisible']==1) { // Invisible User but show to Admin
$username=$loggedin['username'];
$invisibleuser = '*';
} else {
$username=$loggedin['username'];
}
$location=$loggedin['location'];
eval("\$activeusers .= \", ".gettemplate('forumhome_loggedinuser')."\";");
}
}
$DB_site->free_result($loggedins);
$totalonline=$numberregistered+$numberguest;
$numberinvisible=$numberregistered-$numbervisible;
$maxusers=explode(" ", gettemplate('maxloggedin',0,0));
if ((int)$maxusers[0] <= $totalonline) {
$time = time();
$maxloggedin = "$totalonline " . $time;
$DB_site->query("UPDATE template SET template='$maxloggedin' WHERE title='maxloggedin'");
$maxusers[0] = $totalonline;
$maxusers[1] = $time;
}
$recordusers = $maxusers[0];
$recorddate = vbdate($dateformat,$maxusers[1]);
$recordtime = vbdate($timeformat,$maxusers[1]);
eval("\$loggedinusers = \"".gettemplate('forumhome_loggedinusers')."\";");
}
?>
Note for VB guys, if this is against the VB license posting that much code, let me know and I'll delete it.
Is this wrong? Because it still doesn't show all the other users on the main page of the forum.
thincom2000
01-14-2007, 07:22 PM
I should think it would be okay to post all that code, since only forum members with a licensed vBulletin installation can actually read it.
EDIT: Wow, I just realized how old this thread was. Sorry about that, but it does bring up a useful little code snippet!
TheFrienzNet
01-20-2007, 12:59 AM
I should think it would be okay to post all that code, since only forum members with a licensed vBulletin installation can actually read it.
EDIT: Wow, I just realized how old this thread was. Sorry about that, but it does bring up a useful little code snippet!
Haha, from 2001. :D Nice bump;however, a script like this would be good. :D
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.