0

get city from IP is not working on remote server but it works in localhost. Does anyone have any better ideas for getting the city from this class? Sometimes the server remote addr displays this:

 ::1

Here is the code I'm using:

class iplocation{

  public function ipgetCity(){

    $ip=$_SERVER['REMOTE_ADDR'];
    $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=&#8217',$ip));
    $city = stripslashes(ucfirst($addr_details['geoplugin_city']));
    return $city;
} }
i alarmed alien
  • 9,412
  • 3
  • 27
  • 40
SAGAR.G
  • 39
  • 6
  • ::1 is the ip of localhost, you could make sure that the REMOTE_ADDR is the [the external address](http://stackoverflow.com/questions/7909362/how-do-i-get-the-external-ip-of-my-server-using-php ) and geoplugin doesn't always return a city. – pce Oct 16 '14 at 11:50
  • 4
    `file_get_contents('http://www.geoplugin.net/php.gp?ip=’',$ip)` looks wrong, i would expect `file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip)` – Steve Oct 16 '14 at 11:53

0 Answers0