Chinaunix首页 | 论坛 | 博客
  • 博客访问: 606213
  • 博文数量: 263
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 2555
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-26 11:20
文章分类

全部博文(263)

文章存档

2011年(10)

2010年(19)

2009年(170)

2008年(64)

我的朋友

分类:

2009-05-25 18:47:56

Author:David | English Version 【转载时请务必以超链接形式标明文章原始出处和作者信息及】
URL:

首先
下载GeoIP.dat和GeoLiteCity.dat,到网站上找最新的下载,放到/usr/local/share/GeoIP/,将GeoLiteCity.dat该名为GeoIPCity.dat

下载geoip c library:
fetch http:///download/geoip/api/c/GeoIP-1.4.2.tar.gz
tar -xzvf GeoIP-1.4.2.tar.gz
cd GeoIP-1.4.2
./configure --with-city="yes" --with-dbdir=/usr/local/share/GeoIP/
make
make install

从下载geoip的pecl模块:
wget
tar -xzvf geoip-0.2.0.tgz
cd geoip-0.2.0
/home/php/bin/phpize
./configure -enable-geoip -with-php-config=/YOUR_PHP_PATH/bin/php-config
configure出错,configure: error: wrong geoip lib version or lib not found,修改configure,在404x左右行加上 eval "$as_ac_Lib=yes"再configure(我自己的办法,可以用,但不保证没有问题)
make
make install

把生成的geoip.so copy到php extension目录,修改php.ini,加上extension = geoip

/YOUR_PATH_TO_APACHE/bin/apachectl restart

不出意外,应该可以了:)

新建一个php文件,写入下面的文本:

$country = geoip_record_by_name('66.249.72.235'); if ($country) { echo 'This host is located in: '; print_r($country); }

在浏览器浏览,显示入下信息表示成功了:
This host is located in: Array ( [country_code] => US [region] => CA [city] => Mountain View [postal_code] => 94043 [latitude] => 37.4192008972 [longitude] => -122.057403564 [dma_code] => 807 [area_code] => 650 )
用法参考pecl的documentation:


GeoIP服务提供商: http:///app/php

阅读(880) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~