<?
class cocoLOG
{
// returns the new numbr of hits after logging access
function addLogEntry($cocodb,$pageid,$hits)
{
global $HTTP_SERVER_VARS;
global $COCO_CONF_VARS;
$time = time();
// Look up last access from this IP.
$query = "SELECT lasttime FROM $COCO_CONF_VARS[TBACCESS] WHERE";
$query.= " pageid='$pageid' AND ip='$HTTP_SERVER_VARS[REMOTE_ADDR]'";
$query.= "ORDER BY lasttime DESC LIMIT 0,1;";
$answer = $cocodb -> db_query($query);
if($result = $cocodb -> db_fetch_array($answer))
{
$lasttime = $result[0];
}
// Log access
$query = "INSERT INTO $COCO_CONF_VARS[TBACCESS] ";
$query.= "(id,browser,referer,ip,pageid,lasttime) ";
$query.= "VALUES ('','$HTTP_SERVER_VARS[HTTP_USER_AGENT]',";
$query.= "'$HTTP_SERVER_VARS[HTTP_REFERER]',";
$query.= "'$HTTP_SERVER_VARS[REMOTE_ADDR]','$pageid ','$time');";
$cocodb -> db_query ($query);
$this -> accessid = $cocodb -> db_insert_id();
// If last access from this IP happened more than
// RELOADTIMEOUT seconds ago, do count it as a hit.
if((isset($lasttime)) &&
($time - $lasttime > $COCO_CONF_VARS[RELOADTIMEOUT]))
{
// Log to hits as well
$hits += 1;
$query = "UPDATE $COCO_CONF_VARS[TBCOUNTER] ";
$query.= "SET hits='$hits' WHERE id='$pageid';";
$cocodb -> db_query($query);
return $hits;
}
return $hits;
}
}
?>
|