您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php ip获取与判断IP分段类

2024/2/18 6:34:15发布28次查看
php ip获取与判断ip分段类
class ip {
 /**
  * 取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转成整形数值
  * @param string $ip ip
  * @return int
  */
 public static function iptoint($ip) {
  $ips = explode('.',$ip);
  if (count($ips)>=4) {
   $int = $ips[0]*256*256*256+$ips[1]*256*256+$ips[2]
*256+$ips[3];//根据ip,a,b,c类进行计算
  } else {
   throw new exception('ip is error');
  }
  return $int;
 }
/**
  * 判断ip是否在一个ip段内
  * @param string $startip 开始ip
  * @param string $endip 结束ip
  * @param string $ip ip
  * @return bool
  */
 public static function isin($startip, $endip, $ip) {
  $start = ip::iptoint($startip);
  $end = ip::iptoint($endip);
  $ipint = ip::iptoint($ip);
  $result = false;
  if ($ipint>=$start && $ipint   $result = true;
  }
  return $result;
 }
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product