预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

php怎样根据ip地址查地区php怎样根据ip地址查地区很多网站里一打开他们的网页,便显示“江苏无锡的客户您好”等等,请问他们是怎样根据ip查到精确到市的地址的呢?下面是小编整理的php根据ip地址查地区,希望对大家有用,更多消息请关注应届毕业生网。根据discuz里面的ip查询改的/***ip地址所属地区计算*修改自discuz*使用dicuztinyipdata数据文件*将一些英文提示修改为汉字*$is_simpletrue的话显示到市false显示到网通电信等等******/functionconvertip($ip,$is_simple=true,$ipfile='include/data/ip.dat'){$return='';if(!file_exists($ipfile))$ipfile='../'.$ipfile;if(preg_match("/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/",$ip)){$iparray=explode('.',$ip);if($iparray[0]==10||$iparray[0]==127||($iparray[0]==192&&$iparray[1]==168)||($iparray[0]==172&&($iparray[1]>=16&&$iparray[1]<=31))){return'局域网';}elseif($iparray[0]>255||$iparray[1]>255||$iparray[2]>255||$iparray[3]>255){return'ERR';}elseif($is_simple){returnchange_simply_area(convertip_tiny($ip,$ipfile));}else{returnconvertip_tiny($ip,$ipfile);}}}/***从ip文件得到ip所属地区**过滤掉了具体的位置(如网通/电信/**网吧)基本到市***/functionconvertip_tiny($ip,$ipdatafile){static$fp=NULL,$offset=array(),$index=NULL;$ipdot=explode('.',$ip);$ip=pack('N',ip2long($ip));$ipdot[0]=(int)$ipdot[0];$ipdot[1]=(int)$ipdot[1];if($fp===NULL&&$fp=@fopen($ipdatafile,'rb')){$offset=unpack('Nlen',fread($fp,4));$index=fread($fp,$offset['len']-4);}elseif($fp==FALSE){return'-InvalidIPdatafile';}$length=$offset['len']-1028;$start=unpack('Vlen',$index[$ipdot[0]*4].$index[$ipdot[0]*4+1].$index[$ipdot[0]*4+2].$index[$ipdot[0]*4+3]);for($start=$start['len']*8+1024;$start<$length;$start+=8){if($index{$start}.$index{$start+1}.$index{$start+2}.$index{$start+3}>=$ip){$index_offset=unpack('Vlen',$index{$start+4}.$index{$start+5}.$index{$start+6}."\x0");$index_length=unpack('Clen',$index{$start+7});break;}}fseek($fp,$offset['len']+$index_offset['len']-1024);if($index_length['len']){returnmb_convert_encoding(fread($fp,$index_length['len'