TrojanSpot

Anti Flood | www.pemula.info

Oct 28th, 2012
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2. if (!isset($_SESSION)) {
  3.     //session_start();
  4. }
  5.  
  6. // getting informations about user
  7. $useragent = $_SERVER['HTTP_USER_AGENT'];
  8. $bots = "google msnbot lycos scooter fast-webcrawler technorati yahoo bloglines blogsearch gigabot";
  9.  
  10. function get_ip(){
  11. // check if the user's information is already in file
  12.     $ip = getenv("REMOTE_ADDR");
  13.     $file = "ipb.txt";
  14.     $fr = fopen($file, "r") or exit("Fisier indisponibil!");
  15.     $data = fread($fr, filesize($file));
  16.     fclose($fr);
  17.     if (strpos($data,$ip) == FALSE) {
  18.      
  19.         // writing the user's information in a file
  20.         $fw = fopen($file, "a") or exit("Fisier indisponibil!");
  21.         fwrite($fw, "\n" . $ip . "; ");
  22.         fclose($fw);
  23.         }
  24.          
  25.     else {
  26.     $ippos = strpos($data,$ip);
  27.     $pv = strpos($data,';',$ippos);
  28.     $n = strlen($data);
  29.     $j==0;
  30.     for($i=0; $i<$n; $i++){
  31.         if($i==$pv+2){
  32.             $datan[$j]="*";
  33.             $datan[$j+1]=$data[$i]; $j+=2;
  34.             }
  35.         else{
  36.             $datan[$j]=$data[$i]; $j++;
  37.             }
  38.         }
  39.     $frw = fopen($file, "w") or exit("Fisier indisponibil!");
  40.         for($i=0;$i<$j;$i++){
  41.             fwrite($frw, $datan[$i]);
  42.             }
  43.     fclose($frw);
  44.     $datan='';
  45.     }
  46. }
  47.  
  48. // check if the user it's a crawler bot
  49. if (strpos($bots,$useragent) == FALSE) {
  50.  
  51. // anti flood protection
  52. if($_SESSION['last_session_request'] > time() - 4){
  53.         $_SESSION['last_session_request'] = time();
  54.             header("location: /antiflood.html"); get_ip();
  55.             exit;  
  56.          
  57.     }
  58. }
  59.  
  60. $_SESSION['last_session_request'] = time();
  61. ?>
Add Comment
Please, Sign In to add comment