基于IP地址的地理位置- PHP [关闭]

e7arh2l6  于 2024-01-05  发布在  PHP
关注(0)|答案(3)|浏览(116)

**已关闭。**此问题不符合Stack Overflow guidelines。目前不接受回答。

要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于Stack Overflow来说是离题的,因为它们往往会吸引固执己见的答案和垃圾邮件。相反,describe the problem以及到目前为止为解决它所做的工作。
十年前就关门了。
Improve this question
我们正在寻找一种快速,准确的方法来获得基于他们的IP访问者的位置.
我们试过ipinfodb.com,但他们的API使我们的网站在进行API调用时严重滞后。
你还推荐什么服务?

fafcakar

fafcakar1#

获取Geo-IP信息
请求地理IP服务器(netip.de)进行检查,返回IP所在的位置(主机,州,国家,城镇)。

<?php
       $ip='94.219.40.96';
       print_r(geoCheckIP($ip));
       //Array ( [domain] => dslb-094-219-040-096.pools.arcor-ip.net [country] => DE - Germany [state] => Hessen [town] => Erzhausen )

       //Get an array with geoip-infodata
       function geoCheckIP($ip)
       {
               //check, if the provided ip is valid
               if(!filter_var($ip, FILTER_VALIDATE_IP))
               {
                       throw new InvalidArgumentException("IP is not valid");
               }

               //contact ip-server
               $response=@file_get_contents('http://www.netip.de/search?query='.$ip);
               if (empty($response))
               {
                       throw new InvalidArgumentException("Error contacting Geo-IP-Server");
               }

               //Array containing all regex-patterns necessary to extract ip-geoinfo from page
               $patterns=array();
               $patterns["domain"] = '#Domain: (.*?)&nbsp;#i';
               $patterns["country"] = '#Country: (.*?)&nbsp;#i';
               $patterns["state"] = '#State/Region: (.*?)<br#i';
               $patterns["town"] = '#City: (.*?)<br#i';

               //Array where results will be stored
               $ipInfo=array();

               //check response from ipserver for above patterns
               foreach ($patterns as $key => $pattern)
               {
                       //store the result in array
                       $ipInfo[$key] = preg_match($pattern,$response,$value) && !empty($value[1]) ? $value[1] : 'not found';
               }

               return $ipInfo;
       }

?>

字符串

ryoqjall

ryoqjall2#

试试这个http://ip.codehelper.io/
这里是PHP代码。该代码将自动缓存您的请求,因此您的服务器不会发送多个请求。返回IP地址,国家,城市和更多信息。

<?php
// Required Libraries
require_once("ip.codehelper.io.php");
require_once("php_fast_cache.php");

// New Class
$_ip = new ip_codehelper();

// Detect Real IP Address & Location
$real_client_ip_address = $_ip->getRealIP();
$visitor_location       = $_ip->getLocation($real_client_ip_address);

// Output result
echo $visitor_location['Country']."";
echo "<pre>";
print_r($visitor_location);

字符串

ybzsozfc

ybzsozfc3#

Digital Element是这一领域的市场领导者,也是提供企业解决方案的公司。他们提供广泛的API,包括PHP,以访问他们的服务器,您可以在本地安装或通过Web服务访问。他们的数据质量很高,他们的解决方案的性能也很好。MaxMind也是另一个选择,获得了很好的评价。
为了获得最佳的准确性,你会希望选择一个服务或解决方案,你得到每周更新(S),因为这些东西可以在一个给定的网络变化相当多.成本将取决于更新的频率,粒度的地理数据,和额外的字段或数据库的数量你想要.一些供应商提供语言,人口统计,公司,和域名仅举几例.

相关问题