什么是GeoIP ?
所謂GeoIP,就是通過來訪者的IP, 定位他的經緯度,國家/地區,省市,甚至街道等位置信息的一個數據庫。GeoIP有兩個版本,一個免費版,一個收費版本。收費版本的準確率和數據更好一些。
GeoIP如何使用?
GeoIP支持多種語言調用,這里我們以PHP為例。 ?
方法一
通過APT安裝PHP對GeoIP的支持模塊
1 apt-get install php5-geoip libgeoip1下載GeoIP數據庫
1 2 wget -N -q http: // geolite.maxmind.com / download / geoip / database / GeoLiteCity.dat.gz wget -N -q http: // geolite.maxmind.com / download / geoip / database / GeoLiteCountry / GeoIP.dat.gz解壓數據庫
1 gzip -d GeoLiteCity.dat.gz復制GeoIP數據庫到數據目錄
1 cp GeoLiteCity.dat / usr / share / GeoIP / GeoIPCity.dat注:這里的路徑和編譯GeoIP C API所使用的–with-dbdir參數有關。
測試GeoIP
重啟Apaceh
1 / etc / init.d / apache2 restart在Web目錄下新建一個測試的PHP文件,這里以geoip.php為例:
1 2 3 4 5 6 vi / var / www / geoip.php ? < ?php $country = geoip_record_by_name ( '61.128.128.68' ) ; if ( $country ) { echo 'This host is located in: ' ; print_r ( $country ) ; } print geoip_db_filename ( GEOIP_COUNTRY_EDITION ) ; ? >訪問這個文件,如出現下面類似信息,則表示成功了。
1 2 This host is located in : Array ( [ continent_code ] = > AS [ country_code ] = > CN [ country_code3 ] = > CHN [ country_name ] = > China [ region ] = > 33 [ city ] = > Chongqing [ postal_code ] = > [ latitude ] = > 29.562799453735 [ longitude ] = > 106.55280303955 [ dma_code ] = > 0 [ area_code ] = > 0 )方法二
通過源碼方式安裝
安裝GeoIP C API
1 2 3 4 5 6 wget http: // geolite.maxmind.com / download / geoip / api / c / GeoIP.tar.gz tar xvzf GeoIP.tar.gz cd GeoIP-1.4.8 . / configure make make install通過pecl安裝geoip模塊。
1pecl install geoip
啟用GeoIP PHP模塊
1 2 vi / etc / php5 / conf.d / geoip.ini extension =geoip.so復制GeoIP數據庫到數據目錄
1 cp GeoLiteCity.dat / usr / local / share / GeoIP / GeoIPCity.dat注:這里的路徑和編譯GeoIP C API所使用的–with-dbdir參數有關。
測試GeoIP
重啟Apaceh
1 / etc / init.d / apache2 restart在Web目錄下新建一個測試的PHP文件,這里以geoip.php為例:
1 2 3 4 5 6 vi / var / www / geoip.php ? < ?php $country = geoip_record_by_name ( '61.128.128.68' ) ; if ( $country ) { echo 'This host is located in: ' ; print_r ( $country ) ; } print geoip_db_filename ( GEOIP_COUNTRY_EDITION ) ; ? >訪問這個文件,如出現下面類似信息,則表示成功了。
1 2 This host is located in : Array ( [ continent_code ] = > AS [ country_code ] = > CN [ country_code3 ] = > CHN [ country_name ] = > China [ region ] = > 33 [ city ] = > Chongqing [ postal_code ] = > [ latitude ] = > 29.562799453735 [ longitude ] = > 106.55280303955 [ dma_code ] = > 0 [ area_code ] = > 0 )一些編譯中常見的錯誤
如果你的系統中的libtool中的版本低于2.2.6b,可能會出現以下錯誤提示:
1 2 3 libtool: Version mismatch error. This is libtool 2.2.6 Debian-2.2.6a- 4 , but the libtool: definition of this LT_INIT comes from libtool 2.2.6b. libtool: You should recreate aclocal.m4 with macros from libtool 2.2.6 Debian-2.2.6a- 4解決方法:先執行以下語句后,再重新編譯。
1 2 3 4 autoreconf --force . / configure make make install參考文檔
http://www.google.com
http://blog.chinaunix.net/space.php?uid=642374&do=blog&cuid=1944521
http://stackoverflow.com/questions/3096989/libtool-version-mismatch-error
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
