全部博文(263)
分类:
2009-05-25 18:47:56
首先
下载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