Что-то очень странное происходит с этой частью php. Вместо заполнения переменной $ country, она печатает весь json в окне браузера. Я не понимаю, почему он это делает.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://ipinfo.io/".$this_ip."/json");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36");
$headers = array();
$headers[] = 'Referer: http://www.example.com';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$json = curl_exec ($ch);
curl_close ($ch);
$decode = json_decode($json,true);
$country = $decode[country];
Здесь вся ошибка, которую он выплевывает:
<body style="height:100%; overflow:auto; padding:0px; margin:0px;">{
"ip": "8.8.8.8",
"hostname": "google-public-dns-a.google.com",
"city": "Mountain View",
"region": "California",
"country": "US",
"loc": "37.3860,-122.0838",
"org": "AS15169 Google Inc.",
"postal": "94040"
}<br>
<b>Notice</b>: Trying to get property of non-object in <b>/var/www/html/example.php</b> on line <b>59</b><br>
Кроме того, почему я получаю эту ошибку, отличную от объекта?
add curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
к твоему завиту
$country = $decode[country];
в $country = $decode['country'];
вы пропустили '
на вашем ключе массива
Также
$country = $decode['country'];
вместо
$country = $decode[country];
Обратите внимание на то, как вы обращаетесь к деревенскому ключу массива $ decode.