Code:<?php
####################################################################
# IP Tracking #
# #
# Copyright (c) 2003 by Scott Rubin - phpnuke id: scottr #
# http://www.ierealtor.com #
# #
# Insert into the IP Tracking table if $trackip == 1 #
# #
# Delete $ipdel rows from IP Tracking table #
# if number of rows in IP Tracking table reaches $ipmax #
# #
####################################################################
global $prefix, $db, $trackip, $ipmax, $ipdel, $numip, $ipaddr, $hostnm, $exclude_me;
global $hide_ipseg, $hide_host, $ipmaskchar, $members_see_iphost, $members_see_users;
global $show_hits, $offset_hours, $cookie, $user, $admin, $members_see_online, $admin_see_online;
require("modules/IP_Tracking/ipconfig.php");
if ($trackip == 1) {
# capture User, Timestamp, IP Address, Resolved IP Address, Web Page
$dt = date("Y-m-d H:i:s", time() + ($offset_hours * 60 * 60)) ;
$ipaddr = $_SERVER["REMOTE_ADDR"] ;
$hostnm = gethostbyaddr("$ipaddr");
if(is_user($user)) {
cookiedecode($user);
$username=$cookie[1];
}
if(is_admin($admin)) {
if(!is_array($admin)) {
$admin = base64_decode($admin);
$admin = explode(":", $admin);
$username = "$admin[0]";
} else {
$username = "$admin[0]";
}
}
$exclude_me=false;
array_walk($exclude_ips, 'IPTrack_exclude_ip');
if(!$exclude_me) array_walk($exclude_hosts, 'IPTrack_exclude_host');
if (!$exclude_me) {
# concatenate SCRIPT_NAME and QUERY_STRING since REQUEST_URI not used in Windows hosted sites.
# $pg = getenv(REQUEST_URI);
# $pg = getenv(SCRIPT_NAME);
$pg = $_SERVER["SCRIPT_NAME"];
# if ((getenv(QUERY_STRING)) != "") { $pg = $pg . "?" . getenv(QUERY_STRING) ; }
if (($_SERVER["QUERY_STRING"]) != "") { $pg = $pg . "?" . $_SERVER["QUERY_STRING"] ; }
if($username==''){
# let the database insert a null into the username column
$sql = "INSERT INTO ".$prefix."_iptracking (date_time, ip_address, hostname, page)
VALUES ('$dt', '$ipaddr', '$hostnm', '$pg')";
$db->sql_query($sql);
} else {
$sql = "INSERT INTO ".$prefix."_iptracking (username, date_time, ip_address, hostname, page)
VALUES ('$username', '$dt', '$ipaddr', '$hostnm', '$pg')";
$db->sql_query($sql);
}
# Delete from the iptracking table based on parameters set in ipsettings.php
if ($ipmax > 0 and $ipdel > 0 and $ipmax >= $ipdel) {
# replaced for speed v3.1.2
#$tresult = sql_query("SELECT * FROM ".$prefix."_iptracking", $dbi);
#$numrows = sql_num_rows($tresult, $dbi);
$tsql = "SELECT COUNT(*) FROM ".$prefix."_iptracking";
$tresult = $db->sql_query($tsql);
list($numrows) = $db->sql_fetchrow($tresult);
if($numrows>=$ipmax) {
# 'DELETE ... LIMIT' not ready until mysql 4.0
# $tsql = "DELETE FROM ".$prefix."_iptracking ORDER BY date_time LIMIT ".$ipdel;
# $db->sql_query($tsql);
$tsql = "SELECT date_time FROM ".$prefix."_iptracking ORDER BY date_time LIMIT " .$ipdel.",1";
$tresult = $db->sql_query($tsql);
list($date_time) = $db->sql_fetchrow($tresult);
$tsql = "DELETE FROM ".$prefix."_iptracking WHERE date_time <= '".$date_time."'";
$db->sql_query($tsql);
}
}
}
}
function IPTrack_exclude_ip($item) {
# this function checks if the ip address is in the list of ip addresses in the $exclude_ips array
# if it is, set global variable $exclude=true
# wildcard chars are allowed
global $ipaddr, $exclude_me;
if(eregi($item, $ipaddr)) $exclude_me=true;
}
function IPTrack_exclude_host($item) {
# this function checks if the hostname is in the list of hostnames in the $exclude_hosts array
# if it is, set global variable $exclude=true
# wildcard chars are allowed
global $hostnm, $exclude_me;
if(eregi($item, $hostnm)) $exclude_me=true;
}
?>
|