Php restricts ip segment access and prohibits code sharing of ip submission forms. ip form
Add the following code on the page where you want to disable access or submit a form for determination.
Note: The following is only an example code of php ip address restriction. If you want to apply it to CMS, modify it on your own.
<? Php/Add IP address access restriction if (getenv ('HTTP _ CLIENT_IP ') & strcasecmp (getenv ('HTTP _ CLIENT_IP'), 'unknown ')) {$ userip = getenv ('HTTP _ CLIENT_IP ');} elseif (getenv ('HTTP _ X_FORWARDED_FOR') & strcasecmp (getenv ('HTTP _ X_FORWARDED_FOR '), 'unknon') {$ userip = getenv ('HTTP _ X_FORWARDED_FOR ');} elseif (getenv ('remote _ ADDR ') & strcasecmp (getenv ('remote _ ADDR '), 'unknown') {$ userip = getenv ('remote _ ADDR ');} elseif (isse T ($ _ SERVER ['remote _ ADDR ']) & $ _ SERVER ['remote _ ADDR'] & strcasecmp ($ _ SERVER ['remote _ ADDR '], 'unknon') {$ userip = $ _ SERVER ['remote _ ADDR '];} // restrict ip address if ($ userip = '2017. 168.1.88 ') {header ("location: http://t.qq.com/wb631992791"); // jump to Weibo exit after being disabled;} // restrict ip segment $ ip_arr = explode ('. ', $ userip); # The restricted ip segment, which is assumed to be 192. 168. *. * if (! ($ Ip_arr [0] = '000000' & $ ip_arr [1] = '000000') {header ("location: http://t.qq.com/wb631992791 "); // jump to the microblog exit after being banned;} else {header ("location: http://afish.cnblogs.com"); // normal IP Access to the home page of ainemo pavilion exit;}?>
Php Code restricting IP address segment access
<? Php
$ Userip = $ _ SERVER ['remote _ ADDR ']; // obtain the user ip Address
$ Userips = explode (".", $ userip); // cut the obtained ip address into an array.
If ($ userips [0] <= 195 & $ userips [0]> = 195) & ($ userips [1] <=163 & $ userips [1]> = 163) & ($ userips [2] <= 079 & $ userips [2]> = 072) & ($ userips [3] <= 255 & $ userips [3]> = 000 )){
Echo "your ip address does not match! ";
Exit;
} Else {
Echo "verified! ";
}
?>
This is my idea.
Use "." To split the user's IP address into arrays.
Then, separate the restricted IP address with "." into an array.
Then determine whether the user's IP address is in this IP address segment (determine whether the four elements are in this range)
......
Here is a blue ideal for your reference.
------------------
<? Php
Class IP {// obtain the customer IP Address
Function getIpAdr (& $ ip ){
$ Ip1 = getenv ("HTTP_X_FORWARDED_FOR ");
$ Ip2 = getenv ("HTTP_CLIENT_IP ");
$ Ip3 = getenv ("REMOTE_ADDR ");
If ($ ip1 & $ ip1! = 'Unknow ')
$ Ip = $ ip1;
Else if ($ ip2 & $ ip2! = 'Unknow ')
$ Ip = $ ip2;
Else if ($ ip3 & $ ip3! = 'Unknow ')
$ Ip = $ ip3;
Else
$ Ip = '1970. 0.0.1 ';
}
}
Function get_netip ($ myip) {// only the first three IP addresses of the customer are left
$ Temp = explode (".", $ myip );
$ Netip. = $ temp [0];
$ Netip. = ".";
$ Netip. = $ temp [1];
$ Netip. = ".";
$ Netip. = $ temp [2];
Return $ netip;
}
$ Filename = "test. ini"; // defines the operation File
$ Ip_lib = file ($ filename); // read file data to the array
$ Allow = 0;
$ IP = new IP;
$ Thisip = "";
$ IP-> getIpAdr (& $ thisip );
$ Thenetip = get_netip ($ thisip );
For ($ I = 0; $ I <count ($ ip_lib); $ I ++ ){
If (ereg ($ thenetip, $ ip_lib [$ I]) {
$ Allow = 1;
Break;
}
}
If ($ allow = 1 ...... remaining full text>
How can I display webpages with banned IP addresses when I look at a bunch of PHP code?
If (in_array ($ ip, $ blacklist) {// block IP access from the blacklist
Header ('HTTP/1.0 403 Forbidden ');
Echo "Access prohibited ";
Exit;
}