地理区域检测 PHP
我有一个网站,需要根据用户所在的位置向其显示特定数据。例如,如果他们正在查看我在利兹(英国)的网站,我需要显示所有利兹相关数据。我如何在 PHP 中执行此操作?我需要使用访客的 IP 地址吗?
谢谢
I have a website and need to display specific data to the user depending on when they are located. For example, if they are viewing my website in Leeds (UK), I need to display all Leeds related data. How do I do this in PHP? Do I need to use the visitors IP address?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用基于用户 IP 地址的 GeoIP 数据库。 Maxmind 有一个免费的、不太最新的商业数据库版本。从那里,您将数据插入到您选择的数据库中,并对用户的 IP 运行查询。
请注意,检测 IP 地址并不完美。有人可以使用代理服务器、欺骗其 IP,或者可能通过公司 VPN 进行工作,因此他们所在的位置和 IP 表示的位置并不总是匹配。请警惕此限制。
You would need to work with a GeoIP database based on the user's IP address. Maxmind has a free, less up to date version of their commercial database available. From there you insert the data into your database of choice and run queries against the user's IP.
Please note that detecting IP addresses is not perfect. Someone can use a proxy server, spoof their IP, or might be working from a corporate VPN, so where they are and where their IP says they are do not always match. Be wary of this restriction.
查找 PHP 地理 IP。
Look for the PHP Geo IP.
获取用户 IP 并从 maxmind 等公司获取 GEO 数据库/API http://www.maxmind.com/。查找与 IP 相关的各种有用信息,包括城市/位置。
Get the users IP and get a GEO database/API from companies like maxmind http://www.maxmind.com/. Find all sorts of useful information related to the IP, including city/location.