class ip_location
{
function init()
$this-wrydat = 'ip_area.dat';
$this-fp = fopen($this-wrydat, 'rb');
$this-getipnumber();
$this-getwryversion();
$this - REDIRECT_MODE_0 = 0;
$this - REDIRECT_MODE_1 = 1;
}
function get($str)
return $this-$str;
function set($str,$val)
$this-$str = $val;
function getbyte($length,$offset=null)
!is_null($offset) fseek($this-fp, $offset, SEEK_SET);
return fread($this-fp, $length);
function packip($ip)
$chr=null;
$chr .= chr(0);
$var = unpack( 'Vlong', $this-getbyte($length, $offset).$chr);
return $var['long'];
function getwryversion()
$this-wrydat_version = $this-getbyte($length, $this-firstip-$length);
function getipnumber()
$this-firstip = $this-getlong();
$this-lastip = $this-getlong();
function getstring($data='', $offset=NULL)
$char = $this-getbyte(1,$offset);
while(ord($char) 0)
$data .= $char;
$char = $this-getbyte(1);
return $data;
function iplocaltion($ip)
$ip = $this-packip($ip);
$low = 0;
$high = $this-ipnumber-1;
$ipposition = $this-lastip;
while($low = $high)
$high = $t - 1;
else
$low = $t + 1;
break;
return $ipposition;
function getarea()
$b = $this-getbyte(1);
switch(ord($b))
case $this - REDIRECT_MODE_0 :
return '';
case $this - REDIRECT_MODE_1:
default:
return $this-getstring($b);
function getiplocation($ip)
$ippos = $this-iplocaltion($ip);
$this-area = $this-getarea();
$this-country = $this-getstring('',$countryoffset);
$this-country = $this-getstring($b);
$this-area = $this-getarea();
---------------------------------------------------------------
调用方法:
$iploca = new ip_location;
$iploca - init();
$iploca - getiplocation($ip);
$area['country']=='' $area['country']='未知';
$area['area']=='' $area['area']='未知';
return $area;
// 通过$_SERVER变量
echo $_SERVER['SERVER_ADDR'];
// 通过执行操作符,等同于在命令行下执行该命令,要获取ip的根据返回内容截取
$output = +ipconfig+;
echo 'pre'.$output.'/pre';
// 通过system函数,功能与执行操作符一样
echo 'pre';
$last_line = system('ipconfig', $retval);
echo '
/pre
hr /Last line of the output: ' . $last_line . '
hr /Return value: ' . $retval;
以上就是土嘎嘎小编大虾米为大家整理的相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!