_geoip_seek_country
The Google Font Fix geoip seek country function.
Description
Parameters (2)
- 0. $gi
- The gi.
- 1. $ipnum
- The ipnum.
Usage
if ( !function_exists( '_geoip_seek_country' ) ) { require_once ABSPATH . PLUGINDIR . 'google-font-fix/geo/geoip.inc.php'; } // The gi. $gi = null; // The ipnum. $ipnum = null; // NOTICE! Understand what this does before running. $result = _geoip_seek_country($gi, $ipnum);
Defined (1)
The function is defined in the following location(s).
- /geo/geoip.inc.php
- function _geoip_seek_country($gi, $ipnum)
- {
- $offset = 0;
- for ($depth = 31; $depth >= 0; --$depth) {
- if ($gi->flags & GEOIP_MEMORY_CACHE) {
- $buf = _safe_substr(
- $gi->memory_buffer,
- 2 * $gi->record_length * $offset,
- 2 * $gi->record_length
- );
- } elseif ($gi->flags & GEOIP_SHARED_MEMORY) {
- $buf = _sharedMemRead(
- $gi,
- 2 * $gi->record_length * $offset,
- 2 * $gi->record_length
- );
- } else {
- fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0
- or trigger_error("GeoIP API: fseek failed", E_USER_ERROR);
- $buf = fread($gi->filehandle, 2 * $gi->record_length);
- }
- $x = array(0, 0);
- for ($i = 0; $i < 2; ++$i) {
- for ($j = 0; $j < $gi->record_length; ++$j) {
- $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8);
- }
- }
- if ($ipnum & (1 << $depth)) {
- if ($x[1] >= $gi->databaseSegments) {
- return $x[1];
- }
- $offset = $x[1];
- } else {
- if ($x[0] >= $gi->databaseSegments) {
- return $x[0];
- }
- $offset = $x[0];
- }
- }
- trigger_error("GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR);
- return false;
- }