Guest User

PHP ban ips if in file

a guest
Jan 25th, 2013
156
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $lines = file('ips.txt');
  3. $myproto = 'http';
  4. $mywebsiteurl = 'example';
  5. $endingstring = 'com';
  6. // you can use the 3 variables above(myproto, websiteurl, endingstring) in the exit message if you want. you can do {$myproto}://{$mywebsiteurl}.{$endingstring}
  7. // Loop through our array, show HTML source as HTML source; and line numbers too.
  8. foreach ($lines as $line_num => $line) {
  9.     $visitorIP = $_SERVER['REMOTE_ADDR'];
  10.     //DEV TEST: $visitorIP = '90.90.90.90';
  11.     if($line==$visitorIP&&!empty($visitorIP)) {exit('IP Address is blacklisted/banned');
  12.     }
  13. }
  14. ?>
RAW Paste Data