Hi there everyone!
I'm having two problems with some code I've written. First, it's printing the json info to screen although I don't want it to and secondly, I'm having problems retrieving the json info for setting variables.
$ipurl = "http://ipinfo.io/".$ip;
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $ipurl);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
$result = curl_exec($cURL);
$json = json_decode($result, true);
curl_close($cURL);
$hostname = $json[0]['hostname'];
$city = $json['city'];
$region = $json['region'];
$country = $json['country'];
$loc = $json['loc'];
$org = $json['org'];
$postcode = $json['postcode'];
So, it seems
$result = curl_exec($cURL);
is printing the json info to screen. How do I stop this?
and secondly, although I've used json_decode and have tried to set variables but although it prints to screen, trying to use $json['elementname'] leaves me with an empty variable. What do I need to do to set these?
Thanks for your time!