Skip to content

Commit 8b424a4

Browse files
committed
Examples updated
1 parent 48b6e7d commit 8b424a4

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ Pass the _exlcludes_ parameter to get remove the unnecessary fields from the res
5353
<?php
5454
$apiKey = "PUT_YOUR_API_KEY_HERE";
5555
$ip = "CLIENT_IP_ADDRESS";
56-
$response = get_location($apiKey, $ip);
57-
$json = array();
58-
$json = json_decode($response, true);
56+
$location = get_geolocation($apiKey, $ip);
57+
$decodedLocation = json_decode($location, true);
5958

6059
echo "<pre>";
61-
print_r($json);
60+
print_r($decodedLocation);
6261
echo "</pre>";
6362

6463
function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "") {
@@ -106,24 +105,28 @@ Here is an example to get the geolocation for a list of IP addresses and display
106105
echo "<th>ISP</th>";
107106
echo "<th>Languages</th>";
108107
echo "<th>Is EU Member?</th>";
108+
echo "<th>Currency</th>";
109+
echo "<th>Timezone</th>";
109110
echo "</tr>";
110111

111-
foreach($ips as $ip) {
112+
foreach ($ips as $ip) {
112113
$location = get_geolocation($apiKey, $ip);
113-
$decodedLocation = json_decode($location);
114+
$decodedLocation = json_decode($location, true);
114115

115116
echo "<tr>";
116-
echo "<td>$decodedLocation->ip</td>";
117-
echo "<td>$decodedLocation->continent_name ($decodedLocation->continent_code)</td>";
118-
echo "<td>$decodedLocation->country_name ($decodedLocation->country_code2)</td>";
119-
echo "<td>$decodedLocation->organization</td>";
120-
echo "<td>$decodedLocation->isp</td>";
121-
echo "<td>$decodedLocation->languages</td>";
122-
if($decodedLocation->is_eu == true) {
117+
echo "<td>".$decodedLocation['ip']."</td>";
118+
echo "<td>".$decodedLocation['continent_name']." (".$decodedLocation['continent_code'].")</td>";
119+
echo "<td>".$decodedLocation['country_name']." (".$decodedLocation['country_code2'].")</td>";
120+
echo "<td>".$decodedLocation['organization']."</td>";
121+
echo "<td>".$decodedLocation['isp']."</td>";
122+
echo "<td>".$decodedLocation['languages']."</td>";
123+
if($decodedLocation['is_eu'] == true) {
123124
echo "<td>Yes</td>";
124125
} else {
125126
echo "<td>No</td>";
126127
}
128+
echo "<td>".$decodedLocation['currency']['name']."</td>";
129+
echo "<td>".$decodedLocation['time_zone']['name']."</td>";
127130
echo "</tr>";
128131
}
129132
echo "</table>";

0 commit comments

Comments
 (0)