First we recall the IP address $var that was covered
in "PHP post to $var" this will be set to a new $var.
API file $details = ip($ipaddress);
Now we will create a function that can
read the API json API file.
API file function ip($ipaddress) { $json = file_get_contents("https://link/{$ipaddress}"); $details = json_decode($json, true); return $details; }
Now we extract the json details.
Depending on your API you can have more data.
IP address $isp = $details['isp']; $ipaddr = $details['ip'];
The data for the location,
This is not 100% accurate.
Location details $zip = $details['zip']; $city = $details['city']; $region = $details['region']; $country = $details['country']; $timezone = $details['timezone'];
Now we will change the latitude and longitude to one $var so we can use this for the maps.
Location details $location = $details['latitude'] . "," .$details['longitude'];
We will also catch the errors from the API.
Error details $error = $details['error']; $errormsg = $details['errormsg'];