2011-12-12 36 views
3

我可以通過當前主機訪問GeoIP.dat文件,但每輸入一個IP都是空的。任何想法可能是錯誤的或解決它的方法?我有PHP錯誤,但我沒有看到任何錯誤。geopip記錄始終爲空?

這裏是我當前的腳本:

<?php 

include('geoip.inc'); 
include('geoipcity.inc'); 
include('geoipregionvars.php'); 


$gi = geoip_open("GeoIP.dat", GEOIP_STANDARD); 

$rsGeoData = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']); 

echo("<pre>"); 
print_r($rsGeoData); 
echo("</pre>"); 

geoip_close($gi); 

?> 

結果總是看起來是這樣的:

geoiprecord Object 
(
[country_code] => 
[country_code3] => 
[country_name] => 
[region] => 
[city] => 
[postal_code] => 
[latitude] => -180 
[longitude] => -180 
[area_code] => 
[dma_code] => 
[metro_code] => 
[continent_code] => -- 
) 
+1

根據您的網絡服務器的設置,$ _SERVER ['REMOTE_ADDR']可能不包含客戶端的IP地址。嘗試回顯$ _SERVER ['REMOTE_ADDR']以確保IP地址正確。 – SuitedSloth

+0

我想到了這一點,並驗證了它是正確的IP。 – Paul

+0

'var_dump($ _ SERVER ['REMOTE_ADDR']);'輸出? 「geoip_open」和「geoip_record_by_addr」在哪裏定義? 「GeoIP.dat」具體包含哪些內容,它們的格式是什麼標準以及實際數據是什麼? – hakre

回答

2

確保您使用GeoIP的正確版本。我有這個代碼,它工作正常。注意不同的數據庫文件:

include("geoipcity.inc"); 
include("geoipregionvars.php"); 

$gi = geoip_open('geolitecity.dat', GEOIP_STANDARD); 
$record = geoip_record_by_addr($gi, ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') ? '83.238.225.249' : $_SERVER['REMOTE_ADDR']); 
geoip_close($gi); 
+0

顯然我有一箇舊版本。這工作,謝謝! – Paul