【发布时间】:2016-01-04 12:09:00
【问题描述】:
我正在使用以下代码获取国家和城市名称
<?php
$user_ip= getenv('REMOTE_ADDR');
$geo= unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
$city= $geo["geoplugin_city"];
$country= $geo["geoplugin_countryName"];
?>
当我回显时,它会打印国家/地区名称,但对于城市,它会显示
Undefined index: geoplugin_city
将var_dump 用于$geo 我在数组中得到[geoplugin_city] 但当我var_dump($city) i get null 时
请帮帮我
这是我的 var_dump($geo) 结果
Array ( [geoplugin_request] => 83.110.15.6
[geoplugin_status] => 206
[geoplugin_credit] => Some of the returned data includes GeoLite
data created by MaxMind, available
from http://www.maxmind.com.
[geoplugin_city] =>
[geoplugin_region] =>
[geoplugin_areaCode] => 0
[geoplugin_dmaCode] => 0
[geoplugin_countryCode] => AE
[geoplugin_countryName] => United Arab Emirates
[geoplugin_continentCode] => AS
[geoplugin_latitude] => 24
[geoplugin_longitude] => 54
[geoplugin_regionCode] =>
[geoplugin_regionName] =>
[geoplugin_currencyCode] => AED
[geoplugin_currencySymbol] => Dh
[geoplugin_currencySymbol_UTF8] => Dh
[geoplugin_currencyConverter] => 3.6719 )
【问题讨论】:
-
向我们展示
var_dump($geo);只是展示。 -
为什么
geoplugin_city键不能为空? -
看看我的价值请检查我如何从中获得我的城市?
-
有时 geoplugin 不提供城市名称。使用 $city= !empty($geo["geoplugin_city"])?$geo["geoplugin_city"]:'N/A';
-
这是
print_r,如果你使用var_dump- 你会看到geoplugin_city' => string '' (length=0),所以它是一个空字符串。
标签: javascript php jquery geolocation