Skip to content

Commit 3396361

Browse files
Content didn't contain anything
1 parent b8d5aa4 commit 3396361

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

ip-geolocation-api-php.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
<?php
2-
$clientIp = "YOUR_CLIENT_IP";
3-
$apikey = "YOUR_API_KEY";
2+
$clientIp = "CLIENT_IP_ADDRESS";
3+
$apikey = "PUT_YOUR_API_KEY_HERE";
44
$response = get_location($apikey, $clientIp);
5-
$resArr = array();
6-
$resArr = json_decode($response);
7-
echo "<pre>"; print_r($resArr); echo "</pre>";
5+
$json = array();
6+
$json = json_decode($response, true);
87

8+
echo "<pre>";
9+
print_r($json);
10+
echo "</pre>";
11+
912
function get_location($apiKey, $ip = null) {
1013
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip;
1114
$cURL = curl_init();
12-
15+
1316
curl_setopt($cURL, CURLOPT_URL, $url);
1417
curl_setopt($cURL, CURLOPT_HTTPGET, true);
18+
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
1519
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
1620
'Content-Type: application/json',
1721
'Accept: application/json'
1822
));
19-
20-
$content = curl_exec($cURL);
21-
curl_close($cURL);
22-
return $content;
23+
return curl_exec($cURL);
2324
}
2425
?>

0 commit comments

Comments
 (0)