OK I think I goofed. I looked at the sessions table, so here goes.
For registered members, you need it where
userid>0. For guests, it's where
userid=0. So let's revisit the code:
Code:
<?
require("forum/admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassword);
mysql_select_db($dbname);
$cookietimeout = mysql_query("SELECT value FROM setting WHERE varname = cookietimeout");
$datecut = time()-$cookietimeout;
$loggedins=mysql_query("SELECT COUNT(userid) AS users FROM session WHERE lastactivity>$datecut AND userid>0",$db) or die ("oops");
while($loggedin = mysql_fetch_array($loggedins))
$membersonline=number_format($loggedin[users]);
$guestsloggedins=mysql_query("SELECT COUNT(userid) AS users FROM session WHERE lastactivity>$datecut AND userid=0",$db) or die ("oops");
while($guestsloggedin = mysql_fetch_array($guestsloggedins))
$guestsonline=number_format($guestsloggedin[users]);
// rest of code to display numbers
?>
New code is in
red. (I also changed a couple variables, but the new code is highlighted to point out what we did wrong.)
I also added a couple lines to set the date cut without involving global.php.
Use
$membersonline to display the members online, and use
$guestsonline to display the guests.