|
1 | 1 | <?php |
2 | | - $apiKey = "PUT_YOUR_API_KEY_HERE"; |
| 2 | + $apiKey = "YOUR_API_KEY"; |
3 | 3 | $ip = "CLIENT_IP_ADDRESS"; |
4 | | - $location = get_geolocation($apiKey, $ip); |
| 4 | + $location = get_geolocation($apiKey, $ip, "en", "*", "", $include); |
5 | 5 | $decodedLocation = json_decode($location, true); |
6 | 6 |
|
7 | 7 | echo "<pre>"; |
8 | 8 | print_r($decodedLocation); |
9 | 9 | echo "</pre>"; |
10 | | - |
11 | | - function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "") { |
12 | | - $url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes; |
| 10 | + |
| 11 | + function get_geolocation($apiKey, $ip, $lang = "en", $fields = "*", $excludes = "", $include = "") { |
| 12 | + $url = "https://api.ipgeolocation.io/ipgeo?apiKey=".$apiKey."&ip=".$ip."&lang=".$lang."&fields=".$fields."&excludes=".$excludes."&include=".$include; |
13 | 13 | $cURL = curl_init(); |
14 | | - |
15 | 14 | curl_setopt($cURL, CURLOPT_URL, $url); |
16 | 15 | curl_setopt($cURL, CURLOPT_HTTPGET, true); |
17 | 16 | curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); |
18 | 17 | curl_setopt($cURL, CURLOPT_HTTPHEADER, array( |
19 | 18 | 'Content-Type: application/json', |
20 | 19 | 'Accept: application/json' |
21 | 20 | )); |
| 21 | + |
22 | 22 | return curl_exec($cURL); |
23 | 23 | } |
24 | 24 | ?> |
0 commit comments