Пример #1
0
 /**
  * Get the country by IP
  * Return an array with : short name, like 'us', long name, like 'United States and response like 'OK' or <error_message> '
  * @access public
  * @param string $ip
  * @return array
  */
 public function getCountryByIp($ip)
 {
     $country = array(0 => 'unknown', 1 => 'NA', 'response' => 'OK');
     if (Dot_Kernel::validIp($ip) != "public") {
         return $country;
     }
     if (extension_loaded('geoip') == false) {
         // GeoIp extension is not active
         $api = new Dot_Geoip_Country();
         $geoipPath = $this->config->resources->geoip->path;
         if (file_exists($geoipPath)) {
             $country = $api->getCountryByAddr($geoipPath, $ip);
         } else {
             $country['response'] = 'Warning: ' . $this->option->warningMessage->modGeoIp;
         }
     }
     if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_COUNTRY_EDITION) && 'unknown' == $country[0]) {
         //if GeoIP.dat file exists
         $countryCode = geoip_country_code_by_name($ip);
         $countryName = geoip_country_name_by_name($ip);
         $country[0] = $countryCode != false ? $countryCode : 'unknown';
         $country[1] = $countryName != false ? $countryName : 'NA';
     }
     if ('unknown' == $country[0]) {
         // GeoIp extension is active, but .dat files are missing
         $api = new Dot_Geoip_Country();
         $geoipPath = $this->config->resources->geoip->path;
         if (file_exists($geoipPath)) {
             $country = $api->getCountryByAddr($geoipPath, $ip);
         } else {
             $country['response'] = 'Warning: ' . $this->option->warningMessage->modGeoIp;
         }
     }
     return $country;
 }
Пример #2
0
 /**
  * Get GeoIp Version release
  * Return an array with keys "country" & "city"
  * @access public
  * @return array
  */
 public function getGeoIpVersion()
 {
     $return = array('country' => '-', 'city' => '-', 'local' => '-');
     // let's see the version of local .dat file
     $geoipPath = $this->config->resources->geoip->path;
     $geoipVersion = explode(" ", Dot_Geoip_Country::geoipDatabaseInfo($geoipPath));
     $return['local'] = $geoipVersion[0] . ' ' . Dot_Kernel::TimeFormat($geoipVersion[1]);
     // do we have geoIP server-wide ?
     if (function_exists('geoip_database_info')) {
         if (geoip_db_avail(GEOIP_COUNTRY_EDITION)) {
             $info = explode(" ", geoip_database_info(GEOIP_COUNTRY_EDITION));
             $return['country'] = $info[0] . ' ' . Dot_Kernel::TimeFormat($info[1]);
         }
     }
     return $return;
 }