Block IP Range using Wildcard with PHP

Code, Hack on October 17th, 2011 No Comments

 PHP |  copy code |? 01// array’s of banned IP addresses02$bannedIP = array("^10.999.00.*", "^99.88.77.*", "192.168.0.1", "^66.77.*.*");03if(in_array($_SERVER[’REMOTE_ADDR’],$bannedIP)) {04 // this is for exact matches of IP address in array05 header("Location: http://www.domain.com");06 exit();07} else {08 // this is for wild card matches09 foreach($bannedIP as $ip) {10 if(eregi($ip,$_SERVER[’REMOTE_ADDR’])) {11 header("Location: http://www.domain.com");12 exit();13 }14 }15}

Tags: , , ,