Skip to content

Commit d52e6b6

Browse files
Code structuring
1 parent fa388d5 commit d52e6b6

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

ip-geolocation-api-php.php

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
<?php
2-
$clientIp = "YOUR_CLIENT_IP";
3-
$apikey = "YOUR_API_KEY";
2+
$clientIp = "YOUR_CLIENT_IP";
3+
$apikey = "YOUR_API_KEY";
44

5-
$response = get_location($apikey, $clientIp);
6-
$resArr = array();
7-
$resArr = json_decode($response);
8-
echo "<pre>"; print_r($resArr); echo "</pre>";
9-
function get_location($apiKey, $ip = null) {
10-
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip;
11-
$cURL = curl_init();
12-
curl_setopt($cURL, CURLOPT_URL, $url);
13-
curl_setopt($cURL, CURLOPT_HTTPGET, true);
14-
15-
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
16-
'Content-Type: application/json',
17-
'Accept: application/json'
18-
));
19-
20-
$content = curl_exec($cURL);
21-
22-
curl_close($cURL);
23-
24-
return $content;
25-
}
5+
$response = get_location($apikey, $clientIp);
6+
$resArr = array();
7+
$resArr = json_decode($response);
8+
echo "<pre>"; print_r($resArr); echo "</pre>";
9+
10+
function get_location($apiKey, $ip = null) {
11+
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip;
12+
$cURL = curl_init();
13+
14+
curl_setopt($cURL, CURLOPT_URL, $url);
15+
curl_setopt($cURL, CURLOPT_HTTPGET, true);
16+
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
17+
'Content-Type: application/json',
18+
'Accept: application/json'
19+
));
20+
21+
$content = curl_exec($cURL);
22+
curl_close($cURL);
23+
return $content;
24+
}
2625
?>

0 commit comments

Comments
 (0)