从 IP 获取城市在远程服务器上不起作用,但它在 localhost 中起作用。有没有人有更好的想法来从这个班级获得城市?有时服务器远程地址会显示:
::1
这是我正在使用的代码:
class iplocation{
public function ipgetCity(){
$ip=$_SERVER['REMOTE_ADDR'];
$addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=’',$ip));
$city = stripslashes(ucfirst($addr_details['geoplugin_city']));
return $city;
} }