The code is as follows |
Copy Code |
$start =iptoint (' 192.168.1.110 '); $end = Iptoint (' 192.168.0.1 '); $ipInt = Iptoint (get ()); $result = false; if ($ipInt >= $start && $ipInt <= $end) { $result = true; }
if ($result) { Echo ' In the same net segment '; } Else { Echo ' is not in the same net segment '; } |
Not on the same network segment
/*
* IP to reshape numerical value
* @param string $ip IP
* @return int
*/
The code is as follows |
Copy Code |
function Iptoint ($IP) { $ips tutorial = Explode ('. ', $IP); if (count ($ips) >=4) { $int = $ips [0]*256*256*256+ $ips [1]*256*256+ $ips [2]*256+ $ips [3];//] based on the Ip,a,b,c class } else { throw new Exception (' IP is error '); } return $int; } |
/*
* Get User IP address 192.68.0.110
*/
The code is as follows |
Copy Code |
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; } /*
|
Site original Reprint annotated source www.111cn.net
*/