GeoIP庫(kù)怎么在php項(xiàng)目中運(yùn)用?針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到枝江網(wǎng)站設(shè)計(jì)與枝江網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)制作、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋枝江地區(qū)。一、GEOIP數(shù)據(jù)庫(kù)
細(xì)分到國(guó)家:GeoLite Country
細(xì)分到城市:GeoLite City
二、php官方geoip.dll庫(kù)
修改php.ini,啟用geoip庫(kù):
復(fù)制代碼 代碼如下:
extension=php_geoip.dll
追加geoip段,指定數(shù)據(jù)庫(kù)位置:
復(fù)制代碼 代碼如下:
[geoip]
geoip.custom_directory = "D:\php5.3\geo\"
測(cè)試代碼
注意geoip.dll中使用的 GeoIPCity.dat 即 GeoLiteCity.dat,用的時(shí)候注意看提示
復(fù)制代碼 代碼如下:
echo geoip_country_name_by_name( "8.8.8.8" ) . "\n";
print_r( geoip_record_by_name( "8.8.8.8" ) );
echo geoip_country_name_by_name( "61.139.2.69" ). "\n";
print_r( geoip_record_by_name( "61.139.2.69" ) );
三、MaxMind官方php文件函數(shù)庫(kù)
文檔和示例:http://dev.maxmind.com/geoip/downloadable
修改maxmind示例中 sample.php 和 sample_city.php 中 GeoIP.dat/GeoLiteCity.dat 路徑為你自己的路徑
同一目錄用 “./GeoIP.dat” 或 “./GeoLiteCity.dat” 即可。
詳細(xì)到國(guó)家
復(fù)制代碼 代碼如下:
include("geoip.inc");
$gi = geoip_open( "./GeoIP.dat", GEOIP_STANDARD );
echo geoip_country_code_by_addr($gi, "8.8.8.8") . "\t" . geoip_country_name_by_addr($gi, "8.8.8.8") . "\n";
echo geoip_country_code_by_addr($gi, "61.139.2.69") . "\t" . geoip_country_name_by_addr($gi, "61.139.2.69") . "\n";
geoip_close($gi);
詳細(xì)到國(guó)家城市
復(fù)制代碼 代碼如下:
include("geoipcity.inc");
include("geoipregionvars.php");
$gi = geoip_open("./GeoLiteCity.dat",GEOIP_STANDARD);
$record = geoip_record_by_addr($gi,"8.8.8.8");
print $record->country_code . " " . $record->country_code3 . " " . $record->country_name . "\n";
print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n";
print $record->city . "\n";
print $record->postal_code . "\n";
print $record->latitude . "\n";
print $record->longitude . "\n";
print $record->metro_code . "\n";
print $record->area_code . "\n";
print $record->continent_code . "\n";
print "\n-----\n";
$record = geoip_record_by_addr($gi,"61.139.2.69");
print $record->country_code . " " . $record->country_code3 . " " . $record->country_name . "\n";
print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n";
print $record->city . "\n";
print $record->postal_code . "\n";
print $record->latitude . "\n";
print $record->longitude . "\n";
print $record->metro_code . "\n";
print $record->area_code . "\n";
print $record->continent_code . "\n";
geoip_close($gi);
關(guān)于GeoIP庫(kù)怎么在php項(xiàng)目中運(yùn)用問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。