Forum Moderators: coopster

Message Too Old, No Replies

Confused about an IP # inside a script

What would this part mean?

         

LunaC

1:52 am on Mar 3, 2007 (gmt 0)

10+ Year Member



I'm looking at a stat script I'd like to install and ran across this chunk:


if ($_SERVER["REMOTE_ADDR"]!= "###.###.###.###") {
$count = logit($table, $domain, $To, $_SERVER["REMOTE_ADDR"], $_SERVER["HTTP_USER_AGENT"], $servertime, $_SERVER["HTTP_REFERER"], $sites[$sid]['crawler']);
if ($sites[$sid]['counter']) echo $count;
}

The IP # is the part that concerns me, it's a live IP that's seemingly unrelated to the script. So why would it be there and what is it doing?

eelixduppy

2:03 am on Mar 3, 2007 (gmt 0)




So why would it be there

I'm not sure. I guess it would depend.


and what is it doing?

It is not logging the information if the remote address matches the ip in the condition. There may be reasons why it is there but it is not entirely apparent.

LunaC

2:17 am on Mar 3, 2007 (gmt 0)

10+ Year Member



Hmm, well at least that's less concerning than if it was sending the info somewhere else. Perhaps the script author accidentally left his own IP there from testing and not wanting to track his own visits.

I guess I'll email and ask about it.

eelixduppy

2:21 am on Mar 3, 2007 (gmt 0)




than if it was sending the info somewhere else.

Well, I do not know what is in the "logit" function, so I am not sure where it is being "sent".


I guess I'll email and ask about it.

I'm glad you have that option. Ask away! :)

Good luck!

jatar_k

4:02 am on Mar 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you know where the author is then whois the IP, maybe iot's his

look at the logit function, maybe this is phoning home with something it shouldn't

when I find things like this I always assume malicious intent

mind sharing the logit function?

LunaC

6:53 pm on Mar 3, 2007 (gmt 0)

10+ Year Member



I got a reply and he said it was an IP that was hitting his server hard and messing his stats, this was to be a temporary fix for him and wasn't supposed to make it into the released version.

Sounds reasonable but here's the logit function just in case:


/* Function: logit
/* Role: logs a access into proper databases
/* Parameters:
/* - $table: base name for tables
/* - $site: site being audited
/* - $page: page accessed
/* - $ip: ip number of host
/* - $agent: agent string
/* - $time: unix timestamp
/* - $referer: referer string
/* - $visitCutoff: time of inactivity after which visit is considered to be finished, in minutes
/* - $recordCrawler: true or false, depending on if you want to record visits from Crawlers
/* Output: none
/* Created 05/2004
/* Changed heavily 11/2005 to switch to unique IP based stats...
/* Changed heavily 11/2006 to accomodate a function to not record to record visits from crawlers
/* Changed 11/2006 to pull out the referrer and search engine extraction functions
/* Changed 12/2006: added the $visitCutoff parameter (it used to default at 1hour)
/* Changed 01/2007: removed the $visitCutoff parameter (moved into SQL config)
/*********************************************************************************/
function logit($table, $site, $page, $ip, $agent, $time, $referer, $recordCrawler=true) {
global $DEBUG, $server, $user, $password, $base, $config_table;
// $timestart = getmicrotime();
// basic stuff
$hour = date("H", $time);
$day = date("w", $time);
$datestring = date("Y-m-d",$time);
$date = date("Y-m-d H:i:s",$time);
// Connect to database
$c = mysql_connect("$server","$user","$password") or die("<br>Can not connect to database in log_function.php[593]: ".mysql_error());
$db = mysql_select_db("$base",$c) or die("<br>Can not select base in log_function.php[594] ".mysql_error());
// mysql_query("SET NAMES 'utf8'", $c);
// Read configurations
$conf = read_config($config_table, $c);
$save_host = $conf['save_host'];
$engine_id = $conf['engine_id'];
$engine_url = $conf['engine_url'] ;
$engine_kwd = $conf['engine_kwd'];
$engine_charset = $conf['engine_charset'];
$blacklist= $conf['blacklist'];
$seAreRef = $conf['seAreRef'];
$visitCutoff = $conf['visitcutoff'];
// Extracting the OS and webbrowser
list($wb,$os)=split(";",ExtractAgent($agent,$conf[browser_id],$conf[browser_label],$conf[os_id],$conf[os_label]));
$crawlerArray = array ("Crawler", "Googlebot", "Google Adwords");
if ( $recordCrawler ¦¦ (!$recordCrawler && (array_search ($wb,$crawlerArray) === FALSE)) ) {
// If we record crawlers, or if it is not a crawler, go ahead
// Fixing pagename
$page = preg_replace("/\/+/", "/", $page); // replace all // with / in the page url
$page = ereg_replace ("index.html$", "", $page);
$page = ereg_replace ("index.shtml$", "", $page);
$page = ereg_replace ("index.asp$", "", $page);
$page = ereg_replace ("index.xml$", "", $page);
$page = ereg_replace ("index.php$", "", $page);
$page = ereg_replace ("index.php3$", "", $page);
$page = ereg_replace ("index.php4$", "", $page);
$page = ereg_replace ("index.php5$", "", $page);
// SPECIAL ZONEO: / Becomes index.php This should be fixed... FIX ME!
$isindex = substr($page, -1);
if ($isindex == "/") {
$page = $page."index.php";
}
// Find out if this page has been audited yet, and get the index
$pageid = pageid("${table}_pages", $c, $page, $datestring);
if ($pageid == -1) { break;}
// Hour and day of the week
$test = updateCount("${table}_hour", $c, $hour);
$test = updateCount("${table}_day", $c, $day);
// IP Based stats are in a different function
// includes OS, browser, and country stats
ipbased($c,$pageid,$ip,$agent,$time,$conf,$table,$site,$visitCutoff);
// Referrer, search engines, keywords
$how = figureOutRefOrSE ($c, $referer, $site, $table, $engine_id,$engine_url,$engine_kwd,$engine_charset, $blacklist, $date, $pageid,$seAreRef);
// Add page view + way we got here
$pageview = add_access($table,$c,$datestring,$pageid,$how);
}
// Insert access in latest hosts table, even if it is a crawler
$cleanref = cleanText($referer);
$sql3 ="INSERT INTO `${table}_host` VALUES ('$date', '$ip', '', '$page','$cleanref','$agent')";
$res3 = mysql_query($sql3,$c);
// Cleanup the host table, we do not want that many... Just keep the last ones.
// We will keep twice more hosts than keep_hosts so we do not have to clear up the table all the time. This is for the sake of speeeeed!
$req3 = "SELECT COUNT(*) as count FROM ${table}_host";
$res3 = mysql_query($req3,$c);
$tmp=mysql_fetch_array($res3);
if (($tmp['count']-2*$save_host)>0) {
$hostdelete = $tmp['count']-$save_host;
$req3 = "ALTER TABLE `${table}_host` ORDER BY `date`";
$res3 = mysql_query($req3,$c);
$req3 = "DELETE FROM `${table}_host` LIMIT $hostdelete";
$res3 = mysql_query($req3,$c);
$req3 = "OPTIMIZE TABLE `${table}_host` ";
$res3 = mysql_query($req3,$c);
}
// Close database
@mysql_close ($c);
return $pageview;
}
?>

I don't see anything in there but my knowledge of php is just a tad above zero.

eelixduppy

1:49 am on Mar 5, 2007 (gmt 0)



A quick skim of the code doesn't throw any flags. It seems legit.

If you don't feel comfortable most hosts (that I've used, anyway) provide a statistics service. I'm not sure if you have that option? If you are fine with this solution, remove the if statement that's you questioned in your original post.

Best of luck!