forked from IPGeolocation/ip-geolocation-api-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathip-geolocation-api-php.php
More file actions
executable file
·24 lines (21 loc) · 944 Bytes
/
ip-geolocation-api-php.php
File metadata and controls
executable file
·24 lines (21 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
$apiKey = "YOUR_API_KEY";
$ip = "CLIENT_IP_ADDRESS";
$location = get_geolocation($apiKey, $ip, "en", "*", "", $include);
$decodedLocation = json_decode($location, true);
echo "<pre>";
print_r($decodedLocation);
echo "</pre>";
function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "", $include = "") {
$url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes."&include=".$include;
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
return curl_exec($cURL);
}
?>