| Conditions | 1 |
| Paths | 1 |
| Total Lines | 28 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | public function getGeo($ip) |
||
| 8 | { |
||
| 9 | global $di; |
||
| 10 | |||
| 11 | $config = $di->get("configuration")->load("apikey.php"); |
||
| 12 | $access_key = $config["config"]["keyHolder"]["apiKey"]; |
||
| 13 | |||
| 14 | // Initialize CURL: |
||
| 15 | $ch = curl_init('http://api.ipstack.com/'.$ip.'?access_key='.$access_key.''); |
||
| 16 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
||
|
|
|||
| 17 | |||
| 18 | // Store the data: |
||
| 19 | $json = curl_exec($ch); |
||
| 20 | curl_close($ch); |
||
| 21 | |||
| 22 | // Decode JSON response: |
||
| 23 | $api_result = json_decode($json, true); |
||
| 24 | |||
| 25 | // Output the "capital" object inside "location" |
||
| 26 | $data = [ |
||
| 27 | "city" => $api_result['city'] ?? null, |
||
| 28 | "country_name" => $api_result['country_name'] ?? null, |
||
| 29 | "region_name" => $api_result['region_name'] ?? null, |
||
| 30 | "longitude" => $api_result['longitude'] ?? null, |
||
| 31 | "latitude" => $api_result['latitude'] ?? null |
||
| 32 | ]; |
||
| 33 | |||
| 34 | return $data; |
||
| 35 | } |
||
| 37 |