Hi all.. great site, and although there are tons of Nuke and Port support sites, you guys by far are the fastest at responding to people and getting solutions figured out. So congratulations up front...
Ok, on to the hack...
Anyone who uses User-Info type blocks that gains information from the {prefix}_session table knows that once a registered User logs in, a 'ghost' of that User is kept as a Guest until they are dropped (usually about 5 mins). At any rate, this does create a situation where the Guests Online is not very accurate, especially on a busy site. This one-line hack to the mainfile.php will automatically delete any 'ghosts' in the Guests section. There are also some User Info blocks that use their own new table to track surfers, one in particular is Whoiswhere. It'll become plain how to incorporate this hack to any modified table such as that...
Ok, locate the function online section like this:
Code:
function online() {
global $user, $cookie, $prefix, $dbi;
cookiedecode($user);
$ip = getenv("REMOTE_ADDR");
$username = $cookie[1];
if (!isset($username)) {
$username = "$ip";
$guest = 1;
}
$past = time()-1800;
sql_query("DELETE FROM ".$prefix."_session WHERE time < $past", $dbi);
$result = sql_query("SELECT time FROM ".$prefix."_session WHERE uname='$username'", $dbi);
$ctime = time();
if ($row = sql_fetch_array($result, $dbi)) {
sql_query("UPDATE ".$prefix."_session SET uname='$username', time='$ctime', host_addr='$ip', guest='$guest' WHERE uname='$username'", $dbi);
} else {
sql_query("INSERT INTO ".$prefix."_session (username, time, host_addr, guest) VALUES ('$username', '$ctime', '$ip', '$guest')", $dbi);
}
}
Now add the following DELETE query right above $past = time()-1800;
Code:
function online() {
global $user, $cookie, $prefix, $dbi;
cookiedecode($user);
$ip = getenv("REMOTE_ADDR");
$username = $cookie[1];
if (!isset($username)) {
$username = "$ip";
$guest = 1;
}
sql_query("DELETE FROM ".$prefix."_session where uname='$ip'", $dbi);
$past = time()-1800;
sql_query("DELETE FROM ".$prefix."_session WHERE time < $past", $dbi);
$result = sql_query("SELECT time FROM ".$prefix."_session WHERE uname='$username'", $dbi);
$ctime = time();
if ($row = sql_fetch_array($result, $dbi)) {
sql_query("UPDATE ".$prefix."_session SET uname='$username', time='$ctime', host_addr='$ip', guest='$guest' WHERE uname='$username'", $dbi);
} else {
sql_query("INSERT INTO ".$prefix."_session (username, time, host_addr, guest) VALUES ('$username', '$ctime', '$ip', '$guest')", $dbi);
}
}
If you have a block that uses an added table, such as Whoiswhere, just open up the files that come with the block, and find out what the table name is. For Whoiswhere, the table is {prefix}_whoiswhere, so add the following below the {prefix}_session delete query:
Code:
function online() {
global $user, $cookie, $prefix, $dbi;
cookiedecode($user);
$ip = getenv("REMOTE_ADDR");
$username = $cookie[1];
if (!isset($username)) {
$username = "$ip";
$guest = 1;
}
sql_query("DELETE FROM ".$prefix."_whoiswhere where uname='$ip'", $dbi);
sql_query("DELETE FROM ".$prefix."_session where uname='$ip'", $dbi);
$past = time()-1800;
sql_query("DELETE FROM ".$prefix."_session WHERE time < $past", $dbi);
$result = sql_query("SELECT time FROM ".$prefix."_session WHERE uname='$username'", $dbi);
$ctime = time();
if ($row = sql_fetch_array($result, $dbi)) {
sql_query("UPDATE ".$prefix."_session SET uname='$username', time='$ctime', host_addr='$ip', guest='$guest' WHERE uname='$username'", $dbi);
} else {
sql_query("INSERT INTO ".$prefix."_session (username, time, host_addr, guest) VALUES ('$username', '$ctime', '$ip', '$guest')", $dbi);
}
}
This all keeps things neat and tidy. Guests stay in the tables, but as soon as a Guest logs on, they are immediately removed from the table and kept as a User. Enjoy!
- Keith
Zhen-Xjell Nuke Cops Founder
Joined: Nov 14, 2002
Posts: 5939
Posted:
Sun Jan 19, 2003 2:08 pm
Hey that's a great hack Keith, and thanks for sharing. I for one appreciate your kind remarks for the site and must re-inforce that it wouldn't be possible without teamwork. The more folks we have helping out, the better not only for the site, the users seeking help, but also for Nuke as a whole. Spread the word... We want Nuke to succeed for anyone 100% of the time.
_________________ Paul Laudanski, Microsoft MVP Windows-Security
CastleCops: [de] [en] [wiki]
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum