Login
网站首页 > 文章中心 > 其它

包含phpipv4地址归属地数据库的词条

作者:小编 更新时间:2023-08-04 08:23:52 浏览量:104人看过

php用IP查询归属地

class ip_location

{

function init()

$this-wrydat = 'ip_area.dat';

$this-fp = fopen($this-wrydat, 'rb');

$this-getipnumber();

$this-getwryversion();

包含phpipv4地址归属地数据库的词条-图1

$this - REDIRECT_MODE_0 = 0;

$this - REDIRECT_MODE_1 = 1;

}

function get($str)

return $this-$str;

function set($str,$val)

$this-$str = $val;

包含phpipv4地址归属地数据库的词条-图2

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);

包含phpipv4地址归属地数据库的词条-图3

$this-area = $this-getarea();

---------------------------------------------------------------

调用方法:

$iploca = new ip_location;

$iploca - init();

$iploca - getiplocation($ip);

$area['country']=='' $area['country']='未知';

$area['area']=='' $area['area']='未知';

return $area;

php怎样获取本机的ipv4地址

// 通过$_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;

php获取了ip地址,用php怎么获取ip的地理位置?请大虾赐教!

以上就是土嘎嘎小编大虾米为大家整理的相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章