[ Index ]

PHP Cross Reference of Textpattern 4.0.8

title

Body

[close]

/textpattern/publish/ -> log.php (source)

   1  <?php
   2  
   3  /*
   4      This is Textpattern
   5      Copyright 2005 by Dean Allen - all rights reserved.
   6  
   7      Use of this software denotes acceptance of the Textpattern license agreement
   8  
   9  $HeadURL: https://textpattern.googlecode.com/svn/releases/4.0.8/source/textpattern/publish/log.php $
  10  $LastChangedRevision: 2937 $
  11  
  12  */
  13  
  14  
  15  // -------------------------------------------------------------
  16  	function log_hit($status)
  17      {
  18          global $nolog, $logging;
  19          if(!isset($nolog) && $status != '404') {
  20              if($logging == 'refer') {
  21                  logit('refer', $status);
  22              } elseif ($logging == 'all') {
  23                  logit('', $status);
  24              }
  25          }
  26      }
  27  
  28  // -------------------------------------------------------------
  29  	function logit($r='', $status='200')
  30      {
  31          global $siteurl, $prefs, $pretext;
  32          $mydomain = str_replace('www.','',preg_quote($siteurl,"/"));
  33          $out['uri'] = @$pretext['request_uri'];
  34          $out['ref'] = clean_url(str_replace("http://","",serverSet('HTTP_REFERER')));
  35          $ip = serverSet('REMOTE_ADDR');
  36          if (($ip == '127.0.0.1' or $ip == serverSet('SERVER_ADDR')) and serverSet('HTTP_X_FORWARDED_FOR')) {
  37              $ips = explode( ', ', serverSet('HTTP_X_FORWARDED_FOR') );
  38              $ip = $ips[0];
  39          }
  40          $host = $ip;
  41  
  42          if (!empty($prefs['use_dns'])) {
  43              // A crude rDNS cache
  44              if ($h = safe_field('host', 'txp_log', "ip='".doSlash($ip)."' limit 1")) {
  45                  $host = $h;
  46              }
  47              else {
  48                  // Double-check the rDNS
  49                  $host = @gethostbyaddr($ip);
  50                  if ($host != $ip and @gethostbyname($host) != $ip)
  51                      $host = $ip;
  52              }
  53          }
  54  
  55          $out['ip'] = $ip;
  56          $out['host'] = $host;
  57          $out['status'] = $status;
  58          $out['method'] = serverSet('REQUEST_METHOD');
  59          if (preg_match("/^[^\.]*\.?$mydomain/i", $out['ref'])) $out['ref'] = "";
  60  
  61          if ($r=='refer') {
  62              if (trim($out['ref']) != "") { insert_logit($out); }
  63          } else insert_logit($out);
  64      }
  65  
  66  // -------------------------------------------------------------
  67  	function insert_logit($in)
  68      {
  69          global $DB;
  70          $in = doSlash($in);
  71          extract($in);
  72          safe_insert("txp_log", "`time`=now(),page='$uri',ip='$ip',host='$host',refer='$ref',status='$status',method='$method'");
  73      }
  74  
  75  ?>


Generated: Thu May 21 23:03:01 2009 Cross-referenced by PHPXref 0.7