如何在 PHP 中跟踪用户位置/区域

人气:810 发布:2022-10-16 标签: php geolocation ip-address currency region

问题描述

我正在尝试获取用户浏览网站的国家/地区,以便确定在网站上显示的货币.我曾尝试使用以下提供的 GET 脚本:http://api.hostip.info 但它们只返回 XX 时我测试一下.

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.

谢谢.

推荐答案

试试这些:

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

http://www.ip2location.com/

两者都是 IP 地址到国家/地区的数据库,可让您查找给定 IP 地址的来源国家/地区.

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

但请务必注意,这些数据库并非 100% 准确.它们是一个很好的指南,但由于各种原因,您会得到错误的结果.

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.

许多人使用代理来绕过特定国家/地区的屏蔽和过滤器.许多 IP 范围分配给地理分布广泛的公司;您只会得到他们所在的国家/地区,而不是实际机器所在的国家(这对于跟踪 AOL 用户来说一直是个大问题,因为他们显然都住在弗吉尼亚州)IP 范围的控制权有时会在国家/地区之间转移,因此您可能会因此得到错误的结果(尤其是对于较小/连接不太好的国家/地区)

使您的数据库保持最新将缓解其中一些问题,但不会完全解决它们(尤其是代理问题),因此您应该始终考虑到会得到错误结果的事实.

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.

336