The example in this article describes how PHP restricts the range of IP addresses. Share to everyone for your reference. Specifically as follows:
Only IP addresses within a limited range can be accessed
function get_real_ipaddress () {
if (!empty ($_server[' http_client_ip ')) {return
$_server[' http_client_ip '] ;
} ElseIf (!empty ($_server[' http_x_forwarded_for ')) {return
$_server[' http_x_forwarded_for '];
}
Return $_server[' REMOTE_ADDR '];
}
function In_ip_range ($ip, $ip _one, $ip _two = False) {
if (! $ip _two) {return
$ip _one = = $ip;
}
Return Ip2long ($ip _one) *-1 >= ip2long ($IP) *-1 && ip2long ($ip _two) *-1 <= ip2long ($IP) *-1;
}
function Validate_ip () {
$ip = explode (': ', get_real_ipaddress ());
$ip = $ip [0];
if (In_ip_range ($ip, ' 212.76.229.115 ', ' 212.76.229.120 ')) {return
true;
} else if (In_ip_range ($ip, ' 194.78.4.66 ', ' 194.78.4.79 ')} {return
true;
} else if (In_ip_range ($ip, ' 194.8.4.78 ', ' 194.8.4.78 ')) {
return true;
} else if (In_ip_range ($ip, ' 0 ', ' 1 ')) {//local return
true;
}
Header (' location:http://www.jb51.net ');
}
I hope this article will help you with your PHP program design.