[PHP]
01./**
02. * Detect whether the IP that is accessed is a specified allowed IP
* Enter description here ...
04. */
05.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 to be detected split into an array
#限制IP.
if (!in_array ($IP, $ALLOWED _ip)) {
One. foreach ($ALLOWED _ip as $val) {
if (Strpos ($val, ' * ')!==false) {//found with * number substitution
$arr =array ();//
$arr =explode ('. ', $val);
The $BL =true;//is used to record whether there is a successful match in the loop detection.
for ($i =0; $i <4; $i + +) {
if ($arr [$i]!= ' * ') {//is not equal to * will come in the detection, if the * symbol substitute is not checked
if ($arr [$i]!= $check _ip_arr[$i]) {
$BL =false;
break;//stop checking this IP to continue checking the next IP
21.}
22.}
}//end for
if ($BL) {///If True, find a match to be successful returns
return;
. Die;
27.}
28.}
}//end. foreach
Header (' http/1.1 403 Forbidden ');
echo "Access forbidden";
Die;
33.}
34.}
/**
* Detects whether the IP that is accessed is a 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 to be detected split into an array
#限制IP
if (!in_array ($IP, $ALLOWED _ip)) {
foreach ($ALLOWED _ip as $val) {
if (Strpos ($val, ' * ')!==false) {//found with * number substitution
$arr =array ();//
$arr =explode ('. ', $val);
$BL =true;//is used to record whether there is a successful match in the loop detection
for ($i =0; $i <4; $i + +) {
if ($arr [$i]!= ' * ') {//Not equal to * will come in for detection, if the * symbol substitute is not checked
if ($arr [$i]!= $check _ip_arr[$i]) {
$BL =false;
break;//Terminate check this IP continue check next IP
}
}
}//end for
if ($BL) {///If True, find a match to be successful returns
Return
Die
}
}
}//end foreach
Header (' http/1.1 403 Forbidden ');
echo "Access forbidden";
Die
}
}[php]
01.
[PHP]
01.
/**
02. * Get access to IP
* Enter description here ...
06.
07.
08.
09.}
10.
11.
12. Add a call to Check_ip () where it needs to be detected; To This function provides only the specified IP access to the file and provides the IP in the * number wildcard matching multiple IP www.2cto.com
[PHP]
/** * Get access to IP * Enter description here ... */function GetIP () {return isset ($_server["http_x_forwarded_for"])? $_server[" Http_x_forwarded_for "]:(isset ($_server[" http_client_ip "])? $_server[" Http_client_ip "]: $_server[" REMOTE_ADDR "]); } /**
* Get access to IP
* Enter description here ...
*/
function GetIP () {
return Isset ($_server["Http_x_forwarded_for")? $_server["Http_x_forwarded_for"]
:(Isset ($_server["Http_client_ip")? $_server["Http_client_ip"]
: $_server["REMOTE_ADDR"]);
}
Add a call to Check_ip () where it needs to be detected; To This function provides only the specified IP access to the file and provides the IP in the * number wildcard match multiple IP
http://www.bkjia.com/PHPjc/477824.html www.bkjia.com true http://www.bkjia.com/PHPjc/477824.html techarticle [PHP] 01./** 02. * Detects if the IP access is the specified allowed IP. * Enter description here ... */05.function Check_ip () {$ALLOWED _ip=array (192.168.2.*,127.0.0.1,192.16 ...