WC_Geo_IP::_geoip_seek_country_v6
Seek country IPv6.
Method of the class: WC_Geo_IP{}
No Hooks.
Returns
String.
Usage
$WC_Geo_IP = new WC_Geo_IP(); $WC_Geo_IP->_geoip_seek_country_v6( $ipnum );
- $ipnum(int) (required)
- .
WC_Geo_IP::_geoip_seek_country_v6() WC Geo IP:: geoip seek country v6 code WC 10.5.0
public function _geoip_seek_country_v6( $ipnum ) {
// arrays from unpack start with offset 1
// yet another php mystery. array_merge work around
// this broken behaviour
$v6vec = array_merge( unpack( 'C16', $ipnum ) );
$offset = 0;
for ( $depth = 127; $depth >= 0; --$depth ) {
if ( $this->flags & self::GEOIP_MEMORY_CACHE ) {
$buf = $this->_safe_substr(
$this->memory_buffer,
2 * $this->record_length * $offset,
2 * $this->record_length
);
} elseif ( $this->flags & self::GEOIP_SHARED_MEMORY ) {
$buf = @shmop_read(
$this->shmid,
2 * $this->record_length * $offset,
2 * $this->record_length
);
} else {
if ( 0 != fseek( $this->filehandle, 2 * $this->record_length * $offset, SEEK_SET ) ) {
break;
}
$buf = fread( $this->filehandle, 2 * $this->record_length );
}
$x = array( 0, 0 );
for ( $i = 0; $i < 2; ++$i ) {
for ( $j = 0; $j < $this->record_length; ++$j ) {
$x[ $i ] += ord( $buf[ $this->record_length * $i + $j ] ) << ( $j * 8 );
}
}
$bnum = 127 - $depth;
$idx = $bnum >> 3;
$b_mask = 1 << ( $bnum & 7 ^ 7 );
if ( ( $v6vec[ $idx ] & $b_mask ) > 0 ) {
if ( $x[1] >= $this->databaseSegments ) {
return $x[1];
}
$offset = $x[1];
} else {
if ( $x[0] >= $this->databaseSegments ) {
return $x[0];
}
$offset = $x[0];
}
}
self::log( 'GeoIP API: Error traversing database - perhaps it is corrupt?', 'error' );
return false;
}