识别我的网站访问者所在的国家/地区
我想使用 php 识别我的访问者来自哪个国家/地区。 我怎样才能做到这一点?
I want to identify the country my visitors come from using php.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您需要使用 PHP GeoIP 扩展,它允许您通过 IP 定位有关用户的各种信息。 http://us.php.net/geoip
或者您也可以使用 Maxmind 的 API 来访问数据。 http://www.maxmind.com/app/php
You need to use the PHP GeoIP extension that allows you to locate various information about the users via IP. http://us.php.net/geoip
or you can use Maxmind's API to access the data aswell. http://www.maxmind.com/app/php
您需要使用地理定位服务/数据库。
查看 Maxmind API。
You need to use a Geolocation service/database.
Check out the Maxmind API.
我建议您查看 MaxMind 的 GeoIP API:
http://www.maxmind.com/app/ php
I recommend you taking a look at the MaxMind's GeoIP API:
http://www.maxmind.com/app/php
我意识到这是一个老问题,但以防万一人们仍在关注它,请注意这些实用程序的准确性无法保证,您应该谨慎使用它们,特别是如果您开始使用它们的粒度低于国家级搜索。
WhatIsMyIPAddress.com 声称国家/地区级别为 95-99%,但建议美国城市级别为 50-80%(请参阅 http ://whatismyipaddress.com/geolocation-accuracy)。 我的经验是,某些国家/地区的城市级位置准确率甚至更低。
编辑:不确定投票的目的是什么 - 如果这里有不正确的地方,请告诉我们。 我不知道当前有任何 IP 到地理定位技术可以可靠地实现城市级精度。
I realise this is an old question but just in case people are still looking at it, be aware that the accuracy of these utilities is not guaranteed and you should be cautious what you use them for, especially if you start using them for lower granularity than country level searches.
WhatIsMyIPAddress.com claim 95-99% for country level but suggest 50-80% for city level in the USA (see http://whatismyipaddress.com/geolocation-accuracy). My experience is that some countries have an even lower accuracy rate for city level locations.
Edited: Not sure what the vote down is for - if there is something incorrect here please let us know. I am not aware of any current IP to Geo location techniques that allow city level accuracy reliably.
有一个在 PHP 中使用 maximind API 的完整项目 你来自哪里? IP地理定位
There is a complete project using the maximind API in PHP Where are you from? IP Geolocation
您可以在此博客中找到有关如何使用 PHP 查找访问者的城市和国家/地区的更多详细信息 - http://virallangaliya.blogspot.in/2013/04/how-to-find-city-and-country-of-visitor.html
You can find more details about How to find the city and country of the visitor using PHP in this blog - http://virallangaliya.blogspot.in/2013/04/how-to-find-city-and-country-of-visitor.html