/** * @return string|bool */ public function getCountryCode3() { try { return geoip_country_code3_by_name($this->host); } catch (\Exception $e) { return false; } }
/** * Get two or three letter country code. * * @param boolean $threeLetterCode TRUE to return 3-letter country code * * @return string|false Country code or FALSE on failure */ public function getCountryCode($threeLetterCode = false) { // Try overwrite information first if ($countryCode = parent::getCountryCode($threeLetterCode)) { return $countryCode; } if ($threeLetterCode) { return geoip_country_code3_by_name($this->ip); } return geoip_country_code_by_name($this->ip); }
/** * Get GeoIp host information * * @return void */ protected function getGeoIpHostInfo() { if (function_exists('geoip_db_get_all_info') && null !== $this->host && $this->host != '127.0.0.1' && $this->host != 'localhost') { // Get base info by city if ($this->databases['city']) { $data = geoip_record_by_name($this->host); $this->hostInfo['areaCode'] = $data['area_code']; $this->hostInfo['city'] = $data['city']; $this->hostInfo['continentCode'] = $data['continent_code']; $this->hostInfo['country'] = $data['country_name']; $this->hostInfo['countryCode'] = $data['country_code']; $this->hostInfo['countryCode3'] = $data['country_code3']; $this->hostInfo['dmaCode'] = $data['dma_code']; $this->hostInfo['latitude'] = $data['latitude']; $this->hostInfo['longitude'] = $data['longitude']; $this->hostInfo['postalCode'] = $data['postal_code']; $this->hostInfo['region'] = $data['region']; // Else, get base info by country } else { if ($this->databases['country']) { $this->hostInfo['continentCode'] = geoip_continent_code_by_name($this->host); $this->hostInfo['country'] = geoip_country_name_by_name($this->host); $this->hostInfo['countryCode'] = geoip_country_code_by_name($this->host); $this->hostInfo['countryCode3'] = geoip_country_code3_by_name($this->host); } } // If available, get ISP name if ($this->databases['isp']) { $this->hostInfo['isp'] = geoip_isp_by_name($this->host); } // If available, get internet connection speed if ($this->databases['netspeed']) { $netspeed = geoip_id_by_name($this->host); switch ($netspeed) { case GEOIP_DIALUP_SPEED: $this->hostInfo['netspeed'] = 'Dial-Up'; break; case GEOIP_CABLEDSL_SPEED: $this->hostInfo['netspeed'] = 'Cable/DSL'; break; case GEOIP_CORPORATE_SPEED: $this->hostInfo['netspeed'] = 'Corporate'; break; default: $this->hostInfo['netspeed'] = 'Unknown'; } } // If available, get Organization name if ($this->databases['org']) { $this->hostInfo['org'] = geoip_org_by_name($this->host); } } }
protected function setServerCountryCount($data) { $country_code = geoip_country_code3_by_name($data['host']); if (!array_key_exists($country_code, $this->ServerCountryCount['total'])) { $this->ServerCountryCount['total'][$country_code] = 0; } $this->ServerCountryCount['total'][$country_code]++; if ($data['info']['numberOfPlayers'] > 0) { if (!array_key_exists($country_code, $this->ServerCountryCount['active_players'])) { $this->ServerCountryCount['active_players'][$country_code] = 0; } $this->ServerCountryCount['active_players'][$country_code]++; } if ($data['info']['numberOfPlayers'] > 0) { if (!array_key_exists($country_code, $this->ServerCountryCount['player_count'])) { $this->ServerCountryCount['player_count'][$country_code] = 0; } $this->ServerCountryCount['player_count'][$country_code] += $data['info']['numberOfPlayers']; } }
/** * getCountryCode * * Returns the country code for the IP. * * @access protected * @static * @param integer $letters. (default: 3) number of letters the country * code should be formatted to (eg. USA vs US) * @return string */ protected static function getCountryCode($letters = 3) { if ($letters === 3) { return geoip_country_code3_by_name(self::_getIP()); } return geoip_country_code_by_name(self::_getIP()); }