The
Core function code is as follows:
/** * Detect Access IP is the specified allowed IP * Enter description here ... */function check_ip () {$ALLOWED _ip=array (' 192.168.2.* ', ' 127.0.
0.1 ', ' 192.168.2.49 ');
$IP =getip ();
$check _ip_arr= explode ('. ', $IP)//IP split into array #限制IP if (!in_array ($IP, $ALLOWED _ip)) {foreach ($ALLOWED _ip as $val) {
if (Strpos ($val, ' * ')!==false) {//found to have an asterisk substitution character $arr =array ();//$arr =explode ('. ', $val); $BL =true;//is used to record whether there is a match in the Loop detection for ($i =0 $i <4; $i + +) {if ($arr [$i]!= ' * ') {//Not equal to * will come in to detect if the * symbol substitution is not checked if ($arr [$i]!= $check _ip_arr[$i])
{$BL =false;
break;//terminate check this IP to continue checking the next IP}}//end for if ($BL) {//If it is true to find a match that succeeds returns return;
Die
}}//end foreach header (' http/1.1 403 Forbidden ');
echo "Access forbidden";
Die * Access IP * Enter description here ... */function GetIP () {return isset ($_server["http_x_forwarded_for"])? $_se rver["Http_x_forwarded_for"]:(isset ($_server["http_client_ip"])? $_server["Http_Client_ip "]: $_server[" REMOTE_ADDR "]); }
Add the call to Check_ip () where it needs to be detected, and; this function to provide only the specified IP Access file, and to provide a wildcard matching ip in the IP number;