Login   Register  
PHP Classes
elePHPant
Icontem

File: coco.log.php4

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Matthias Richter  >  phpMyCoCo  >  coco.log.php4  >  Download  
File: coco.log.php4
Role: ???
Content type: text/plain
Description: access log class
Class: phpMyCoCo
Author: By
Last change:
Date: 2001-03-11 13:45
Size: 1,487 bytes
 

Contents

Class file image Download
<?
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;
   }
}
?>