Logo Search packages:      
Sourcecode: dacode version File versions  Download package

nospider.php3

<?php
/**
 * Class to jam the bad spider
 *
 * daCode http://www.dacode.org/
 * src/phplib/nospider.php3
 * $Id: nospider.php3,v 1.24.2.3 2002/05/15 17:27:04 jbcombes Exp $
 */
Class nospider {
      /**
       * Address of remote site
       *@var string
       */
      var $REMOTE_ADDR;

      /**
       * Db abstraction layer
       *@var object Db
       */
      var $db;

      /**
       * Class constructor
       *@global array $HTTP_SERVER_VARS
       */
      Function Nospider() {
            global $HTTP_SERVER_VARS;
            $this->REMOTE_ADDR = $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']?
                        $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']:
                        $HTTP_SERVER_VARS['REMOTE_ADDR'];

            $this->db = LoadClass('Db');
      }

      /**
       * Check how many hits a remote address has made.
       * Calls echo on failure (SQL or too many hits)
       * Calls exit if host has reach maximum number of hits / min
       *@return mixed integer -1 if SQL failed; void if success
       *@access public
       */
      Function check() {
            global $config;

            $ts = $this->utils->unix_stamp_to_timestamp14( time() - 60);

            $sqlc_q = "SELECT count(host) FROM ".$config->tables['nospider'].
                  " WHERE timestamp > ".$ts." AND host='".addslashes($this->REMOTE_ADDR).
                  "'";
            $ret = $this->db->query($sqlc_q);
            if (!$ret) {
                  echo lecho("SQL Failed: ").$this->db->error();
                  return -1;
            }
            $row = $this->db->fetch_array();

            if ($row['count(host)'] > $config->numberofhits) {
                  echo lecho("you bad boy...")."\n";
                  exit;
            } else {
                  $sqlc_q = "INSERT INTO ".$config->tables['nospider'].
                        " (host) VALUES ('".addslashes($this->REMOTE_ADDR)."')";
                  $ret = $this->db->query($sqlc_q);
                  if (!$ret) {
                        echo lecho("SQL Failed: ").$this->db->error();
                        return -1;
                  }
            }
      }
}

?>

Generated by  Doxygen 1.6.0   Back to index