private function getCountryCodeForIP() { try { $ip = $_SERVER['REMOTE_ADDR']; $rawJSON = HttpSimple\get('https://freegeoip.net/json/' . $ip); $info = json_decode($rawJSON); if (!is_object($info) || !isset($info->country_code)) { Log\warn("Web-service at FreeGeoIP.net did not return expected value for IP address {$ip}"); return null; } else { return $info->country_code; } } catch (\SpareParts\WebClient\NetworkError $e) { Log\error("Network error occurred when attempting to lookup IP adress info: " . $e->getMessage()); return null; } }
protected function warn($msg) { Log\warn($msg); }