如何在PHP中跟踪用户的位置/区域 [英] How to track users location / region in PHP

查看:188
本文介绍了如何在PHP中跟踪用户的位置/区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户浏览网站的国家/地区,以便我可以确定在网站上显示的货币。我尝试过使用可用的GET脚本: http://api.hostip.info ,但他们只是在返回XX时我测试它。



如果有人知道任何更好的方法,请分享。



谢谢。

解决方案

试试这些: b -country.webhosting.info/rel =nofollow> http://ip-to-country.webhosting.info/



http://www.ip2location.com/



两者都是IP地址到国家/地区数据库,它允许您查找给定IP地址的来源国家。



但是,重要的是要注意这些数据库不是100 %准确。他们是一个很好的指导,但由于各种原因你会得到错误的结果。


  • 很多人使用代理来绕过国家/特定块和过滤器。

  • 许多IP范围分配给地理分布广泛的公司;你只会得到他们所在的国家,而不是真正的机器所在的国家(这通常是跟踪AOL用户的一个大问题,因为他们都显然居住在弗吉尼亚州)

  • IP范围的控制有时会在国家/地区间传输,因此您可能会得到错误结果(特别是对于较小/连接不良的国家/地区)。


使数据库保持最新将缓解其中的一些问题,但不会完全解决它们(特别是代理问题),所以您应该始终考虑到会得到错误结果的事实。 / p>

I'm trying to get the country from which the user is browsing the website so I can work out what currency to show on the website. I have tried using the GET scripts available from: http://api.hostip.info but they just return XX when I test it.

If anyone knows any better methods please share.

Thanks.

解决方案

Try these:

http://ip-to-country.webhosting.info/

http://www.ip2location.com/

Both are IP address-to-country databases, which allow you to look up the country of origin of a given IP address.

However it's important to note that these databases are not 100% accurate. They're a good guide, but you will get false results for a variety of reasons.

  • Many people use proxying to get around country-specific blocks and filters.
  • Many IP ranges are assigned to companies with large geographic spread; you'll just get the country where they're based, not where the actual machine is (this always used to be a big problem for tracking AOL users, because they were all apparently living in Virginia)
  • Control of IP ranges are sometimes transferred between countries, so you may get false results from that (especially for smaller/less well-connected countries)

Keeping your database up-to-date will mitigate some of these issues, but won't resolve them entirely (especially the proxying issue), so you should always allow for the fact that you will get false results.

这篇关于如何在PHP中跟踪用户的位置/区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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