_geoip_seek_country

The Google Font Fix geoip seek country function.

Description

_geoip_seek_country( $gi, $ipnum ); 

Parameters (2)

0. $gi
The gi.
1. $ipnum
The ipnum.

Usage

  1. if ( !function_exists( '_geoip_seek_country' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-font-fix/geo/geoip.inc.php'; 
  3.  
  4. // The gi. 
  5. $gi = null; 
  6.  
  7. // The ipnum. 
  8. $ipnum = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _geoip_seek_country($gi, $ipnum); 
  12.  

Defined (1)

The function is defined in the following location(s).

/geo/geoip.inc.php  
  1. function _geoip_seek_country($gi, $ipnum) 
  2. $offset = 0; 
  3. for ($depth = 31; $depth >= 0; --$depth) { 
  4. if ($gi->flags & GEOIP_MEMORY_CACHE) { 
  5. $buf = _safe_substr
  6. $gi->memory_buffer,  
  7. 2 * $gi->record_length * $offset,  
  8. 2 * $gi->record_length 
  9. ); 
  10. } elseif ($gi->flags & GEOIP_SHARED_MEMORY) { 
  11. $buf = _sharedMemRead
  12. $gi,  
  13. 2 * $gi->record_length * $offset,  
  14. 2 * $gi->record_length 
  15. ); 
  16. } else { 
  17. fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0 
  18. or trigger_error("GeoIP API: fseek failed", E_USER_ERROR); 
  19. $buf = fread($gi->filehandle, 2 * $gi->record_length); 
  20. $x = array(0, 0); 
  21. for ($i = 0; $i < 2; ++$i) { 
  22. for ($j = 0; $j < $gi->record_length; ++$j) { 
  23. $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8); 
  24. if ($ipnum & (1 << $depth)) { 
  25. if ($x[1] >= $gi->databaseSegments) { 
  26. return $x[1]; 
  27. $offset = $x[1]; 
  28. } else { 
  29. if ($x[0] >= $gi->databaseSegments) { 
  30. return $x[0]; 
  31. $offset = $x[0]; 
  32. trigger_error("GeoIP API: Error traversing database - perhaps it is corrupt?", E_USER_ERROR); 
  33. return false;