| Conditions | 4 |
| Paths | 6 |
| Total Lines | 49 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | public function toJson($ip) : array |
||
| 24 | { |
||
| 25 | $apiKey = $config["ip"]; |
||
|
|
|||
| 26 | |||
| 27 | if (filter_var($ip, FILTER_VALIDATE_IP)) { |
||
| 28 | $valid = "true"; |
||
| 29 | } else { |
||
| 30 | $valid = "false"; |
||
| 31 | } |
||
| 32 | |||
| 33 | if ($valid == "true") { |
||
| 34 | if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
||
| 35 | $ipv = "Ipv4"; |
||
| 36 | } else { |
||
| 37 | $ipv = "Ipv6"; |
||
| 38 | } |
||
| 39 | |||
| 40 | $domain = gethostbyaddr($ip); |
||
| 41 | $details = json_decode(file_get_contents("http://api.ipstack.com/{$ip}?access_key={$apiKey["key"]}")); |
||
| 42 | |||
| 43 | $lat = $details->latitude; |
||
| 44 | $long = $details->longitude; |
||
| 45 | $country = $details->country_name; |
||
| 46 | $region = $details->region_name; |
||
| 47 | $city = $details->city; |
||
| 48 | |||
| 49 | return [ |
||
| 50 | "valid" => $valid, |
||
| 51 | "ip" => $ip, |
||
| 52 | "ipv" => $ipv, |
||
| 53 | "domain" => $domain, |
||
| 54 | "lat" => $lat, |
||
| 55 | "long" => $long, |
||
| 56 | "country" => $country, |
||
| 57 | "region" => $region, |
||
| 58 | "city" => $city |
||
| 59 | ]; |
||
| 60 | |||
| 61 | } else { |
||
| 62 | return [ |
||
| 63 | "valid" => "Not Valid IP", |
||
| 64 | "ip" => null, |
||
| 65 | "ipv" => null, |
||
| 66 | "domain" => null, |
||
| 67 | "lat" => null, |
||
| 68 | "long" => null, |
||
| 69 | "country" => null, |
||
| 70 | "region" => null, |
||
| 71 | "city" => null |
||
| 72 | ]; |
||
| 76 |