I need to get user's current location and save it to the database. I have this small snippet in PHP and Js from ipinfo.io
But PHP code does not work, the js version does.
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
echo $details->city; // -> outputs nothing
<script>
    $.get("http://ipinfo.io", function(response) {
   console.log(response.city);//logged my current city
    }, "jsonp");
</script>
Any idea how to achieve the PHP version?
update
I tried
  var_dump($details)
Shows me
  object(stdClass)[1]
  public 'ip' => string '::1' (length=3)
  public 'hostname' => string 'localhost' (length=9)
  public 'city' => null
  public 'country' => string 'AU' (length=2)
  public 'loc' => string '-27.0000,133.0000' (length=17)
I am testing it in localhost and my country is Philippines