Skip to content

Commit 08d77d6

Browse files
committed
Handle error message on error returned by API
1 parent 8b424a4 commit 08d77d6

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

.gitignore

100644100755
File mode changed.

LICENSE

100644100755
File mode changed.

README.md

100644100755
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,30 @@ Here is an example to get the geolocation for a list of IP addresses and display
114114
$decodedLocation = json_decode($location, true);
115115

116116
echo "<tr>";
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) {
124-
echo "<td>Yes</td>";
117+
118+
if ($decodedLocation['message'] != '') {
119+
echo "<td>".$ip."</td>";
120+
echo "<td>".$decodedLocation['message']."</td>";
125121
} else {
126-
echo "<td>No</td>";
122+
echo "<td>".$decodedLocation['ip']."</td>";
123+
echo "<td>".$decodedLocation['continent_name']." (".$decodedLocation['continent_code'].")</td>";
124+
echo "<td>".$decodedLocation['country_name']." (".$decodedLocation['country_code2'].")</td>";
125+
echo "<td>".$decodedLocation['organization']."</td>";
126+
echo "<td>".$decodedLocation['isp']."</td>";
127+
echo "<td>".$decodedLocation['languages']."</td>";
128+
129+
if ($decodedLocation['is_eu'] == true) {
130+
echo "<td>Yes</td>";
131+
} else {
132+
echo "<td>No</td>";
133+
}
134+
135+
echo "<td>".$decodedLocation['currency']['name']."</td>";
136+
echo "<td>".$decodedLocation['time_zone']['name']."</td>";
127137
}
128-
echo "<td>".$decodedLocation['currency']['name']."</td>";
129-
echo "<td>".$decodedLocation['time_zone']['name']."</td>";
130138
echo "</tr>";
131139
}
140+
132141
echo "</table>";
133142

134143
function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "") {

ip-geolocation-api-php.php

100644100755
File mode changed.

0 commit comments

Comments
 (0)