This file can be added and supports Class c ip addresses, for example, ip.txt... hosts, and Class c ip addresses, for example:
ip.txt 192.168 211.67.188 211.67.191.25
The PHP instance code is as follows:
The above code can be used to cheat you, and the following code will be upgraded:
$ V) {if (! Strstr ($ v, "-") {$ preg_limit. = makePregIP ($ v);} else {$ aipNum = explode ("-", $ v); for ($ I = $ aipNum [0]; $ I <= $ aipNum [1]; $ I ++) {$ preg. = $ preg? "| ". $ I :"[". $ I;} $ preg_limit. = strrpos ($ preg_limit ,". ", 1) = (strlen ($ preg_limit)-1 )? $ Preg. "]": ". ". $ preg. "]" ;}} else {$ preg_limit. = $ str. ". ";} return $ preg_limit;} private function getAllBlockIP () {if ($ this-> Block_ip) {foreach ($ this-> Block_ip as $ k => $ v) {$ ipaddres = $ this-> makePregIP ($ v-> start_ip); $ ip = str_ireplace (". ",". ", $ ipaddres); $ ip = str_replace (" * "," [0-9] {1, 3} ", $ ip); $ ipaddres = "/". $ ip. "/"; $ ip_list [] = $ ipaddres;} return $ ip_list;} p Ublic function checkIP () {$ iptable = $ this-> getAllBlockIP (); $ IsJoined = true; // obtain the user ip address $ Ip = $ this-> get_client_ip (); $ Ip = trim ($ Ip); // remove the IP segment in the blacklist if ($ iptable) {foreach ($ iptable as $ value) {if (preg_match ("{$ value}", $ Ip) {$ IsJoined = false; break ;}}} // perform the following operations if (! $ IsJoined) {echo "IP Error"; exit ;}} private function get_client_ip () {if (getenv ("HTTP_CLIENT_IP") & strcasecmp (getenv ("HTTP_CLIENT_IP "), "unknown") $ ip =
Getenv ("HTTP_CLIENT_IP ");
Else if (getenv ("HTTP_X_FORWARDED_FOR") & strcasecmp (getenv ("HTTP_X_FORWARDED_FOR"), "unknown") $ ip = getenv ("HTTP_X_FORWARDED_FOR ");
Else if (getenv ("REMOTE_ADDR") & strcasecmp (getenv ("REMOTE_ADDR"), "unknown") $ ip = getenv ("REMOTE_ADDR ");
Else if (isset ($ _ SERVER ['remote _ ADDR ']) & $ _ SERVER ['remote _ ADDR '] & strcasecmp ($ _ SERVER ['remote _ ADDR'], "unknown ")) $ ip = $ _ SERVER ['remote _ ADDR '];
Else $ ip = "unknown ";
Return ($ ip );
}
}
?>
Reference the snippet. the code is as follows:
$oBlock_ip = new block_ip(); $oBlock_ip->checkIP();
Tutorial link:
Reprint at will ~ However, please keep the tutorial address★