PDA

View Full Version : # Users Online Not Working With 2.0


BabyU
03-16-2001, 10:47 PM
I had a #online users hack that was working great in 1.x, but returns an error in 2.0

There is a file called online.php that consists of:

------------------------------------------------------------------------
<?php
chdir($DOCUMENT_ROOT . "/forums");
require($DOCUMENT_ROOT . "/forums/global.php");

$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session WHERE userid=0");
$guests=$loggedins[sessions];
$loggedins=$DB_site->query_first("SELECT COUNT(sessionid) AS sessions FROM session WHERE userid<>0");
$members=$loggedins[sessions];

echo "There are currently $members forum members and
$guests guests online. <a href=/forums/index.php>Join us!</a>";

?>

------------------------------------------------------------------------

It is called to a non-php homepage via an include statement:

<!--#include virtual="/forums/online.php"-->

The error I am now receiving since upgrading to 2.0 is:

----------------------------------------------------------------------
There seems to have been a slight problem with the database. Please try again by pressing the refresh button in your browser.

An E-Mail has been dispatched to our Technical Staff, who you can also contact if the problem persists.

We apologise for any inconvenience.
----------------------------------------------------------------------

Any suggestions to fix this? Thanks!

03-16-2001, 10:48 PM
<a href="http://vbulletin.com/forum/showthread.php?s=&goto=lastpost&threadid=10471" target="_blank">http://vbulletin.com/forum/showthrea...threadid=10471</a>

03-16-2001, 10:52 PM
This isn't the same hack that I was referring to in that post. This only showed the number of registered members & guests currently online (shown on a non-vb page).

Is it still affected by the last active location?

03-16-2001, 10:56 PM
Sorry, didn't read it properly...

When you see such a message as this:

There seems to have been a slight problem with the database. Please try again by pressing the refresh button in your browser.

An E-Mail has been dispatched to our Technical Staff, who you can also contact if the problem persists.

We apologise for any inconvenience.

Look in the html-source; It contains more information about what kind of error etc..

03-16-2001, 11:56 PM
I viewed the source code and used the additional information to correct that problem. The user session info is not in global.php anymore, but rather /admin/sessions.php . Easy enough.

Fixed that. It also appears that there is no longer a variable called 'sessionid' . It looks like it is now 'sessionhash' . So I changed that in the hack code.

Now I get the following error:

Fatal error: Call to a member function on a non-object in /home/sites/site14/web/boards/admin/sessions.php on line 70

The online.php file now looks like this:
-----------------------------------------------------------------------<?php
chdir($DOCUMENT_ROOT . "/boards");
require($DOCUMENT_ROOT . "/boards/admin/sessions.php");

$loggedins=$DB_site->query_first("SELECT COUNT(sessionhash) AS sessions FROM session WHERE userid=0");
$guests=$loggedins[sessions];
$loggedins=$DB_site->query_first("SELECT COUNT(sessionhash) AS sessions FROM session WHERE userid<>0");
$members=$loggedins[sessions];

echo "There are currently $members forum members and
$guests guests online. <a href=/boards/index.php>Join us!</a>";

?>
-----------------------------------------------------------------------

So close ... yet so far away! I feel like I'm missing one tiny detail. Can anyone else see what it is?

03-17-2001, 12:10 AM
Just look at what index.php does!

03-17-2001, 12:34 AM
Sometimes the obvious is easily overlooked. Thank you Freddie -- working like a charm ;)

03-17-2001, 05:42 AM
Can you post the code here? I would love to use this!

03-17-2001, 10:43 AM
Save the following as online.php and upload to the forums directory.

-----------------------------------------------------------------------
<?php
chdir($DOCUMENT_ROOT . "/forums");
require($DOCUMENT_ROOT . "/forums/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 ASC, username ASC");
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;

}

echo "There are currently $numberregistered member(s) and $numberguest guest(s) on the boards. <a href=/boards/index.php>Join us!</a>";

?>
-----------------------------------------------------------------------

Call it into your non-vb page via

<!--#include virtual="/forums/online.php"-->

Thank you Freddie & Mas*Mind!

03-17-2001, 03:40 PM
One thing about this code you need to be aware of!

This ONLY works if the visitor has visited your forums before. If they visit this page BEFORE they visit your forums this code will return an error message. :(

I have been working on a fix for a while now, but have not figured it out as of yet.

03-24-2001, 04:58 AM
Call it into your non-vb page via

<!--#include virtual="/forums/online.php"-->

where must i enter this???????????

03-24-2001, 08:22 AM
Why don't you just check the page they came from to get to the online.php if they came from anything but index.php then redirect them to that page.

That solves your problem.

03-24-2001, 11:45 PM
Originally posted by GameGalaxy
Why don't you just check the page they came from to get to the online.php if they came from anything but index.php then redirect them to that page.

That solves your problem.

Because I don't want to FORCE visitors to go to my forums as soon as they visit my website.

03-25-2001, 12:08 AM
Then just have it not display for those that haven't been to the forums.

03-25-2001, 10:24 AM
I don't see the problem that you are referring to. Try going to http://www.20ishparents.com and let me know if you get the error that you are referring to. I checked it from several different computers that had never visited their forums yet, and the message still displayed properly for me.

Charon -- you enter that into the .shtml page where you want it to display how many visitors & guests are online. Mine is in my header file.