IP segmentation class for IP acquisition and judgment of PHP
Class Ip {
/**
* Take IP
* @return String
*/
public static function get () {
if ($_server[' http_client_ip '] && $_server
[' Http_client_ip ']!= ' unknown ') {
$ip = $_server[' http_client_ip '];
} elseif ($_server[' http_x_forwarded_for ') && $_server
[' http_x_forwarded_for ']!= ' unknown ') {
$ip = $_server[' http_x_forwarded_for '];
} else {
$ip = $_server[' remote_addr ';
}
return $IP;
}
/**
* IP to reshape value
* @param string $IP IP
* @return int
*/ public static function Iptoint ($IP) {
$ips = Explode ('. ', $ip);
if (Count ($ips) & gt;=4) {
$int = $ips [0]*256*256*256+ $ips [1]*256*256+ $ips [2]
*256+ $ips [3];//calculated according to the Ip,a,b,c class
} else {
throw new Exception (' IP is error ');
 &NBSP}
return $int;
/**
* Determine if IP is in an IP segment
* param string $startIp Start IP
* @param string $endIp End IP
* @param string $IP IP
* @return b OOL
*/
public static function IsIn ($startIp, $endIp, $ip) {
$start = Ip::iptoint ($sta RTIP);
$end = Ip::iptoint ($endIp);
$ipInt = Ip::iptoint ($IP);
$result = false;
if ($ipInt >= $start && $ipInt <= $end) {
$result = true;
& nbsp;}
return $result;
}
}