Advertisement
w3tools_info

anti_ddos.php

Dec 21st, 2011
2,973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.90 KB | None | 0 0
  1. <?php
  2. /*
  3. Posted @ http://www.w3tools.info/2011/12/anti-ddos-php-script.html
  4. */
  5.  function getIP () {
  6.  if (getenv ("HTTP_CLIENT_IP") and preg_match ("/^[ 0-9 \ .]*?[ 0-9 \ .]+$/ is ", getenv (" HTTP_CLIENT_IP ")) and getenv (" HTTP_CLIENT_IP ") ! = '127 .0.0.1 ') {
  7.  $ Ip = getenv ("HTTP_CLIENT_IP");
  8.  } Elseif (getenv ("HTTP_X_FORWARDED_FOR") and preg_match ("/^[ 0-9 \ .]*?[ 0-9 \ .]+$/ is ", getenv (" HTTP_X_FORWARDED_FOR ")) and getenv (" HTTP_X_FORWARDED_FOR " !) = '127 .0.0.1 ') {
  9.  $ Ip = getenv ("HTTP_X_FORWARDED_FOR");
  10.  } Else {
  11.  $ Ip = getenv ("REMOTE_ADDR");
  12.  }
  13.  return $ ip;
  14.  }
  15.  $ Ad_ip = getIP ();
  16.  
  17.  $ Ad_source = file ("{$ ad_dir} / {$ ad_black_file}");
  18.  $ Ad_source = explode ('', $ ad_source [0]);
  19.  if (in_array ($ ad_ip, $ ad_source)) {die ();}
  20.  
  21.  $ Ad_source = file ("{$ ad_dir} / {$ ad_white_file}");
  22.  $ Ad_source = explode ('', $ ad_source [0]);
  23.  if (! in_array ($ ad_ip, $ ad_source)) {
  24.  
  25.  $ Ad_source = file ("{$ ad_dir} / {$ ad_temp_file}");
  26.  $ Ad_source = explode ('', $ ad_source [0]);
  27.  if (! in_array ($ ad_ip, $ ad_source)) {
  28.  $ Ad_file = fopen ("{$ ad_dir} / {$ ad_temp_file}", "a +");
  29.  $ Ad_string = $ ad_ip. '  ';
  30.  fputs ($ ad_file, "$ ad_string");
  31.  fclose ($ ad_fp);
  32.  ?>
  33. <!--
  34.  
  35.  The site is currently subject to DDOS attack, if you're not a machine, zombie attacking the site, click on the button, otherwise your IP (<?=$ ad_ip?>) Will be blocked!
  36.  <form method="post">
  37.  <input type="submit" name="ad_white_ip" value="Knopka">
  38.  </ Form>
  39. -->
  40.  
  41. <?php
  42.  die ();
  43.  }
  44.  elseif ($ _POST ['ad_white_ip']) {
  45.  $ Ad_file = fopen ("{$ ad_dir} / {$ ad_white_file}", "a +");
  46.  $ Ad_string = $ ad_ip. '  ';
  47.  fputs ($ ad_file, "$ ad_string");
  48.  fclose ($ ad_fp);
  49.  }
  50.  else {
  51.  $ Ad_file = fopen ("{$ ad_dir} / {$ ad_black_file}", "a +");
  52.  $ Ad_string = $ ad_ip. '  ';
  53.  fputs ($ ad_file, "$ ad_string");
  54.  fclose ($ ad_fp);
  55.  die ();
  56.  }
  57.  }
  58.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement