stop the spamming....

Σε αυτή την περιοχή μπορείτε να βρείτε ή να αναζητήσετε πληροφορίες σχετικές με την PHP

Συντονιστές: WebDev Moderators, Super-Moderators, PHP Moderators

Απάντηση
nickred
Δημοσιεύσεις: 128
Εγγραφή: 08 Οκτ 2004 04:32
Επικοινωνία:

stop the spamming....

Δημοσίευση από nickred » 14 Σεπ 2005 01:22

ψαχνοντας στο νετ να βρω τι μπορει να γινει για τις μηχανες αναζητησεις ή οτι αλλο ειναι που καταναλωνουν πορους των σελιδων μας βρηκα το παρακατω:

Κώδικας: Επιλογή όλων

<?php
 
//   ENGLISH-LANGUAGE VERSION&#58; 
 
/*
Notes...
    * $itime is the minimum number of seconds between visits _on average_ over 
      $itime*$imaxvisit seconds.  So in the example, a visitor isn't blocked 
      if it  visits the script multiple times in the first 5 seconds, as long
      as it doesn't visit more than 60 times within 300 seconds &#40;5 minutes&#41;.
    * If the limit is reached, $ipenalty is the number of seconds a visitor
      has to wait before being allowed back. 
An MD5 hash is made of each visitor's IP address, and the last 3 hex digits of that hash are used to generate one of a possible 4096 filenames.  If it is a new visitor, or a visitor who hasn't been seen for a while, the timestamp of the file is set to the then-current time; otherwise, it must be a recent visitor, and the time stamp is increased by $itime. 
If the visitor starts loading the timer script more rapidly than $itime seconds per visit,the time stamp on the IP-hashed filename will be increasing faster than the actual time is increasing.  If the time stamp gets too far ahead of the current time, the visitor is branded a bad visitor and the penalty is applied by increasing the time stamp on its file even further.
4096 separate hash files is enough that it's very unlikely you'll get two visitors at exactly the same time with the same hash, but not so many that you need to keep tidying up the files.
&#40;Even if you do get more than one visitor with the same hash file at the same time, it's no great disaster&#58; they'll just approach the throttle limit a little faster, which in most cases won't matter, as the limits in the example--5/60/60--are quite generous.&#41;
This script can be simply included in each appropriate php script with this&#58;
  //   Spam-Block&#58;
  include&#40;'timer.inc'&#41;;
*/
 
  // INITIALIZATIONS&#58;
 
  //   Constants&#58;
 
  //     Fixed&#58;
  $crlf=chr&#40;13&#41;.chr&#40;10&#41;;
  $itime=5;  // minimum number of seconds between one-visitor visits
  $imaxvisit=60;  // maximum visits in $itime x $imaxvisits seconds
  $ipenalty=60;  // seconds before visitor is allowed back
  $iplogdir="../logs/";
  $iplogfile="ErrantIPs.Log";
 
  //     Language-dependent&#58;
  $spammer1='The Server is momentarily under heavy load.';
  $spammer2='Please wait ';
  $spammer3=' seconds and try again.';
 
 
 
  // OPERATION&#58;
 
  //   Make Check&#58;
 
  //     Get file time&#58;
  $ipfile=substr&#40;md5&#40;$_SERVER&#91;"REMOTE_ADDR"&#93;&#41;,-3&#41;;  // -3 means 4096 possible files
  $oldtime=0;
  if &#40;file_exists&#40;$iplogdir.$ipfile&#41;&#41; $oldtime=filemtime&#40;$iplogdir.$ipfile&#41;;
 
  //     Update times&#58;
  $time=time&#40;&#41;;
  if &#40;$oldtime<$time&#41; $oldtime=$time;
  $newtime=$oldtime+$itime;
 
  //     Stop overuser&#58;
  if &#40;$newtime>=$time+$itime*$imaxvisit&#41;
  &#123;
    //     block visitor&#58;
    touch&#40;$iplogdir.$ipfile,$time+$itime*&#40;$imaxvisit-1&#41;+$ipenalty&#41;;
    header&#40;"HTTP/1.0 503 Service Temporarily Unavailable"&#41;;
    header&#40;"Connection&#58; close"&#41;;
    header&#40;"Content-Type&#58; text/html"&#41;;
    echo '<html><head><title>Overload Warning</title></head><body><p align="center"><strong>'
          .$spammer1.'</strong>'.$br;
    echo $spammer2.$ipenalty.$spammer3.'</p></body></html>'.$crlf;
    //     log occurrence&#58;
    $fp=@fopen&#40;$iplogdir.$iplogfile,"a"&#41;;
    if &#40;$fp!==FALSE&#41;
    &#123;
      $useragent='<unknown user agent>';
      if &#40;isset&#40;$_SERVER&#91;"HTTP_USER_AGENT"&#93;&#41;&#41; $useragent=$_SERVER&#91;"HTTP_USER_AGENT"&#93;;
      @fputs&#40;$fp,$_SERVER&#91;"REMOTE_ADDR"&#93;.' on '.date&#40;"D, d M Y, H&#58;i&#58;s"&#41;.' as '.$useragent.$crlf&#41;;
    &#125;
    @fclose&#40;$fp&#41;;
    exit&#40;&#41;;
  &#125;
 
  //     Modify file time&#58;
  touch&#40;$iplogdir.$ipfile,$newtime&#41;;
 
?> 
το συγκεκριμενο μπορει και γραφεις τις πληροφοριες σε ενα txt αρχειο που το οριζουμε εμεις.

η ιστοσελιδα βρισκεται εδω:
http://forums.digitalpoint.com/showthread.php?t=7918

Απάντηση

Επιστροφή στο “PHP Προγραμματισμός”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 1 επισκέπτης