Skip to content

Commit f68b864

Browse files
authored
Update ip-geolocation-api-php.php
1 parent 2f8ae84 commit f68b864

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

ip-geolocation-api-php.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
21
<?php
2+
$clientIp = "YOUR_CLIENT_IP";
3+
$ipkey = "YOUR_API_KEY";
34

4-
$response = get_web_page("https://api.ipgeolocation.io/ipgeo?apiKey=YOUR_API_KEY&ip=103.255.5.105");
5+
$response = get_location($ipkey, $clientIp);
56
$resArr = array();
67
$resArr = json_decode($response);
78
echo "<pre>"; print_r($resArr); echo "</pre>";
8-
9-
function get_web_page($url) {
10-
$cURL = curl_init();
11-
curl_setopt($cURL, CURLOPT_URL, $url);
12-
curl_setopt($cURL, CURLOPT_HTTPGET, true);
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);
1314

1415
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
15-
'Content-Type: application/json',
16-
'Accept: application/json'
16+
'Content-Type: application/json',
17+
'Accept: application/json'
1718
));
1819

19-
$content = curl_exec($cURL);
20+
$content = curl_exec($cURL);
2021

21-
curl_close($cURL);
22+
curl_close($cURL);
2223

23-
return $content;
24+
return $content;
2425
}
25-
?>
26+
?>

0 commit comments

Comments
 (0)