Error "trying to get property of non-object" when using ipinfo.io

1

I'm relatively new to PHP and I started messing with a site. And I found the following code that was giving error:

<?php        
 function ip_details() {
  $json = file_get_contents("http://ipinfo.io/");
  $details = json_decode($json);
  return $details;
 }
 $details = ip_details();
 $ip = $details->ip;//34    
 $local = $details->city;  //35
?>

This is the error that appears to me:

  

A PHP error was encountered   Severilty: Notice   Message: trying to get property of non-object   Filename: views / login_view.php   Line Number: 34

I know something about PHP but I did not understand what I was looking for here, but I did not find anything that would make me understand what that code was.

Does anyone notice this code that I can explain?

    
asked by anonymous 23.06.2015 / 19:02

1 answer

2

@Bruno Gibellino,

This script takes details of ip, city, region, country, location that can be used to find you in google maps for example.

test, put echo before ip and also $details->city , it will show your ip and where you live.

    
23.06.2015 / 19:10