0

I'm looking to create a basic IP tracker, I'm trying to figure out how to echo certain aspects of this variable, cheers:

{"ip":"MY IP","country_code":"GB","country_name":"United Kingdom","region_code":"ENG","region_name":"England","city":"MY CITY","zip_code":"MY CODE","time_zone":"Europe/London","latitude":----,"longitude":-----,"metro_code":-}

This is the code which I was reading up on:

$location = file_get_contents('http://freegeoip.net/json/'.$_SERVER['REMOTE_ADDR']);
print_r($location);

{
  "ip": "77.99.179.98",
  "country_code": "GB",
  "country_name": "United Kingdom",
  "region_code": "H9",
  "region_name": "London, City of",
  "city": "London",
  "zipcode": "",
  "latitude": 51.5142,
  "longitude": -0.0931,
  "metro_code": "",
  "areacode": ""

}

Cheers!

George
  • 65
  • 6

1 Answers1

3

To echo something do

//Example
      $locationObject = json_decode($location);
      echo $locationObject->ip; 
//Prints out: 77.99.179.98 

More info http://www.dyn-web.com/tutorials/php-js/json/decode.php