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] => --
)
根據您的網絡服務器的設置,$ _SERVER ['REMOTE_ADDR']可能不包含客戶端的IP地址。嘗試回顯$ _SERVER ['REMOTE_ADDR']以確保IP地址正確。 – SuitedSloth
我想到了這一點,並驗證了它是正確的IP。 – Paul
'var_dump($ _ SERVER ['REMOTE_ADDR']);'輸出? 「geoip_open」和「geoip_record_by_addr」在哪裏定義? 「GeoIP.dat」具體包含哪些內容,它們的格式是什麼標準以及實際數據是什麼? – hakre