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


