IP到国家的问题 [英] IP to Country Problem

查看:86
本文介绍了IP到国家的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




i需要获取网站访问者的国家/地区,因此我下载了所有国家/地区的数据库及其相应的IP但未采用虚线格式,

但它无法获得我的国家,虽然它已在数据库中列出但似乎数据库中没有IP ..

i使用ip2long()函数转换IP生成9个数字虽然我国家数据库中的所有IP都是10个数字,所以脚本无法显示我的国家......任何人都有答案吗?

解决方案

< blockquote>您在搜索查询中使用的数据格式必须与数据库中的数据格式匹配,否则数据库将无法返回正确的结果(显然)。


因此,您必须知道如何数据库中的数据格式化,以便您可以将访问者的IP地址转换为该格式。


所以真正的问题是:如何格式化数据库中的数据?

有些e xamples会很好。


如果没有这些信息,我们无法帮助你。


那就是CountryIp DB的样本:

展开 | 选择 | Wrap | 行号


你确定它们全部 10个字符长吗?


根据我的测试,所有以58或更低开头的IP地址都是9个字符。

部分日本应属于该组。你的数据库对该区域有什么看法?


你还应该注意因为PHP的整数是有符号的,所以ip2long函数给出的一些长值会导致负数值,这可能不是你想要使用的。


要将实际的unsigned long作为字符串,你可以这样做:

展开 | 选择 | < span class =codeLinkonclick =WordWrap(this);> Wrap | 行号


Hi ,

i need to get the country of the visitor of the site so i downloaded a DB of all the countries and their corresponding IPs but not in Dotted format ,
but it fails to get my country although it''s listed in the DB but seems the IP is not present in the DB ..
i convert the IP using ip2long() function which generates 9 numbers ALthough all the IPs in the DB for my country are 10 numbers so the script fails to show my Country ...anyone have an answer for this ??

解决方案

The format of the data you use in your search query must match the format of the data in your database, or the database will not return correct results (obviously).

Therefore, you must know how the data in your database is formatted so you can convert the IP address of your visitors into that format.

So the real question is: how is the data in the database formatted?
Some examples would be good.

Without that info there is little we can do to help you.


Well, thats a sample of the CountryIp DB :

Expand|Select|Wrap|Line Numbers


Are you sure they are all 10 characters long?

According to my tests, all IP addresses starting with 58 or less will be 9 chars.
Parts of Japan should belong to that group. What does your DB say about that zone?

You should also note that the because PHP''s integers are signed, some of the long values given by the ip2long function will result in negative values, which is probably not what you want to be using.

To get the actual unsigned long as a string, you can do something like:

Expand|Select|Wrap|Line Numbers


这篇关于IP到国家的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆