|
1 | 1 | <?php |
2 | | -$clientIp = "YOUR_CLIENT_IP"; |
3 | | -$apikey = "YOUR_API_KEY"; |
| 2 | + $clientIp = "YOUR_CLIENT_IP"; |
| 3 | + $apikey = "YOUR_API_KEY"; |
4 | 4 |
|
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 | + } |
26 | 25 | ?> |
0 commit comments