The php restricted IP segment code was found when I searched for related solutions on the internet. the logic of the makePregIP function of this class is a bit problematic. I modified it and can use it, this function allows access from IP addresses in the whitelist. if you want to restrict IP addresses in the blacklist... the php restricted IP segment code was found when I searched for related solutions on the internet. the logic of the makePregIP function of this class is a bit problematic. I modified it and can use it, this function allows access from IP addresses in the whitelist. to restrict access from IP addresses in the blacklist, simply modify the code logic in the checkIP function.
The code is as follows:
CheckIP () {echo 'Your IP address is: '; echo $ oBlock_ip-> ip address; exit ('Access prohibited') ;}?>
The allowIP file code is as follows:
Allow_ip = $ allow_ip; $ this-> ip = '';} private function makePregIP ($ str) {if (strstr ($ str ,"-")) {$ aIP = explode (". ", $ str); foreach ($ aIP as $ k => $ v) {if (! Strstr ($ v, "-") {$ preg_limit. = $ this-> makePregIP ($ v); $ preg_limit. = ". ";}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-> allow_ip) {$ I = 1; foreach ($ this-> allow_ip as $ k => $ v) {$ ipaddres = $ this-> makePregIP ($ v ); $ ip = str_ireplace (". ",". ", $ ipaddres); $ ip = str_replace (" * "," [0-9] {1, 3} ", $ ip); $ ipaddres = "/". $ ip. "/"; $ ip_list [] = $ ipaddres; $ I ++ ;}}return $ ip_list;} pub Lic function checkIP () {$ iptable = $ this-> getAllBlockIP (); $ IsJoined = false; // obtain the user ip address $ Ip = $ this-> get_client_ip (); $ Ip = trim ($ Ip); // in the whitelist, if ($ iptable) {foreach ($ iptable as $ value) {if (preg_match ("{$ value}", $ Ip) {$ IsJoined = true; break ;}}// if (! $ IsJoined) {return false;} return true;} private function get_client_ip () {if (getenv ("HTTP_CLIENT_IP") & strcasecmp (getenv ("HTTP_CLIENT_IP "), "unknown") $ ip = getenv ("HTTP_CLIENT_IP"); else if (getenv ("condition") & strcasecmp (getenv ("HTTP_X_FORWARDED_FOR"), "unknown ")) $ ip = getenv ("HTTP_X_FORWARDED_FOR"); else if (getenv ("REMOTE_ADDR") & strcasecmp (getenv ("REMOTE_ADDR"), "u Nknown ") $ 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"; $ this-> ip = $ ip; return ($ ip) ;}}?>
Tutorial address:
Reprinted! But please include the article address ^