function _get_region($gi, $ipnum) { if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV0; if ($seek_region >= 1000) { $country_code = "US"; $region = chr(($seek_region - 1000) / 26 + 65) . chr(($seek_region - 1000) % 26 + 65); } else { $country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region]; $region = ""; } return array($country_code, $region); } else { if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV1; //print $seek_region; if ($seek_region < US_OFFSET) { $country_code = ""; $region = ""; } else { if ($seek_region < CANADA_OFFSET) { $country_code = "US"; $region = chr(($seek_region - US_OFFSET) / 26 + 65) . chr(($seek_region - US_OFFSET) % 26 + 65); } else { if ($seek_region < WORLD_OFFSET) { $country_code = "CA"; $region = chr(($seek_region - CANADA_OFFSET) / 26 + 65) . chr(($seek_region - CANADA_OFFSET) % 26 + 65); } else { $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE]; $region = ""; } } } return array($country_code, $region); } } }
function _get_record($gi, $ipnum) { $seek_country = _geoip_seek_country($gi, $ipnum); if ($seek_country == $gi->databaseSegments) { return NULL; } // workaround php's broken substr, strpos, etc handling with // mbstring.func_overload and mbstring.internal_encoding $enc = mb_internal_encoding(); mb_internal_encoding('ISO-8859-1'); $record_pointer = $seek_country + (2 * $gi->record_length - 1) * $gi->databaseSegments; if ($gi->flags & GEOIP_MEMORY_CACHE) { $record_buf = substr($gi->memory_buffer, $record_pointer, FULL_RECORD_LENGTH); } elseif ($gi->flags & GEOIP_SHARED_MEMORY) { $record_buf = @shmop_read($gi->shmid, $record_pointer, FULL_RECORD_LENGTH); } else { fseek($gi->filehandle, $record_pointer, SEEK_SET); $record_buf = fread($gi->filehandle, FULL_RECORD_LENGTH); } $record = new geoiprecord(); $record_buf_pos = 0; $char = ord(substr($record_buf, $record_buf_pos, 1)); $record->country_code = $gi->GEOIP_COUNTRY_CODES[$char]; $record->country_code3 = $gi->GEOIP_COUNTRY_CODES3[$char]; $record->country_name = $gi->GEOIP_COUNTRY_NAMES[$char]; $record->continent_code = $gi->GEOIP_CONTINENT_CODES[$char]; $record_buf_pos++; $str_length = 0; // Get region $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1)); while ($char != 0) { $str_length++; $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1)); } if ($str_length > 0) { $record->region = substr($record_buf, $record_buf_pos, $str_length); } $record_buf_pos += $str_length + 1; $str_length = 0; // Get city $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1)); while ($char != 0) { $str_length++; $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1)); } if ($str_length > 0) { $record->city = substr($record_buf, $record_buf_pos, $str_length); } $record_buf_pos += $str_length + 1; $str_length = 0; // Get postal code $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1)); while ($char != 0) { $str_length++; $char = ord(substr($record_buf, $record_buf_pos + $str_length, 1)); } if ($str_length > 0) { $record->postal_code = substr($record_buf, $record_buf_pos, $str_length); } $record_buf_pos += $str_length + 1; $str_length = 0; // Get latitude and longitude $latitude = 0; $longitude = 0; for ($j = 0; $j < 3; ++$j) { $char = ord(substr($record_buf, $record_buf_pos++, 1)); $latitude += $char << $j * 8; } $record->latitude = $latitude / 10000 - 180; for ($j = 0; $j < 3; ++$j) { $char = ord(substr($record_buf, $record_buf_pos++, 1)); $longitude += $char << $j * 8; } $record->longitude = $longitude / 10000 - 180; if (GEOIP_CITY_EDITION_REV1 == $gi->databaseType) { $metroarea_combo = 0; if ($record->country_code == "US") { for ($j = 0; $j < 3; ++$j) { $char = ord(substr($record_buf, $record_buf_pos++, 1)); $metroarea_combo += $char << $j * 8; } $record->metro_code = $record->dma_code = floor($metroarea_combo / 1000); $record->area_code = $metroarea_combo % 1000; } } mb_internal_encoding($enc); return $record; }
public function _get_region($ipnum) { if ($this->databaseType == self::GEOIP_REGION_EDITION_REV0) { $seek_region = $this->_geoip_seek_country($ipnum) - self::GEOIP_STATE_BEGIN_REV0; if ($seek_region >= 1000) { $country_code = "US"; $region = chr(($seek_region - 1000) / 26 + 65) . chr(($seek_region - 1000) % 26 + 65); } else { $country_code = $this->GEOIP_COUNTRY_CODES[$seek_region]; $region = ""; } return array($country_code, $region); } else { if ($this->databaseType == self::GEOIP_REGION_EDITION_REV1) { $seek_region = _geoip_seek_country($ipnum) - self::GEOIP_STATE_BEGIN_REV1; //print $seek_region; if ($seek_region < self::US_OFFSET) { $country_code = ""; $region = ""; } else { if ($seek_region < self::CANADA_OFFSET) { $country_code = "US"; $region = chr(($seek_region - self::US_OFFSET) / 26 + 65) . chr(($seek_region - self::US_OFFSET) % 26 + 65); } else { if ($seek_region < self::WORLD_OFFSET) { $country_code = "CA"; $region = chr(($seek_region - self::CANADA_OFFSET) / 26 + 65) . chr(($seek_region - self::CANADA_OFFSET) % 26 + 65); } else { $country_code = $this->GEOIP_COUNTRY_CODES[($seek_region - self::WORLD_OFFSET) / self::FIPS_RANGE]; $region = ""; } } } return array($country_code, $region); } } }
function _get_record($gi, $ipnum) { $seek_country = _geoip_seek_country($gi, $ipnum); if ($seek_country == $gi->databaseSegments) { return null; } return _common_get_record($gi, $seek_country); }