首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用MaxMind的GeoLite获取区域名称

使用MaxMind的GeoLite获取区域名称
EN

Stack Overflow用户
提问于 2012-12-15 22:01:01
回答 1查看 2.9K关注 0票数 0

我对如何获取区域名称感到有点困惑,并且找不到任何关于它的文档。我已经安装了数据库'GeoIP.dat‘和'geoip.inc’在目录'...IP GeoLite\GeoLite‘,我还有一个测试\IP GeoLite\find.php的php页面,'find.php’页面内的代码是它不工作:

代码语言:javascript
复制
<?php
/* Instead of having to determine the country of the client every time they visit the site we are going to set 
a cookie so that any other script in PHP or Javascript can use the region information. 
The user is also given a menu option to change the region and reset the cookie to a new value.
Likewise, if it already exists we don't want to change it.
We start off by checking that the cookie called Region exists. 
If it does, the job is nearly done and we simply set the $Region variable so that we can refresh 
the cookie at the end of the program by recreating it. */
 if(isset($_COOKIE['Region']))
 {
  $Region = $_COOKIE['Region'];
 }
 else
/* Only if the cookie isn't set do we do the actions in the else part of the if, 
so this makes the whole thing efficient.
To make use of the GeoLite code we have to load the include file: */
{ 
  $GeoPath= 'GeoLite/'; 
  include($GeoPath.'geoip.inc'); 
}
  $countrydata = GeoIP_region_name_by_code(gir->country_code, gir->region) ;
  echo $countrydata ;
?>
EN

回答 1

Stack Overflow用户

发布于 2013-01-02 12:22:06

必须先打开Geo IP二进制数据文件

代码语言:javascript
复制
// Open Geo IP binary data file
$geoIp = geoip_open($GeoPath.'GeoIP.dat',GEOIP_STANDARD);

请查看此文档http://www.maxmind.com/download/geoip/api/php.old/README

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13892852

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档