WC_Geo_IP::_geoip_seek_country()privateWC 1.0

Seek country.

Method of the class: WC_Geo_IP{}

No Hooks.

Return

String.

Usage

// private - for code of main (parent) class only
$result = $this->_geoip_seek_country( $ipnum );
$ipnum(int) (required)
-

WC_Geo_IP::_geoip_seek_country() code WC 8.6.1

private function _geoip_seek_country( $ipnum ) {
	$offset = 0;
	for ( $depth = 31; $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 );
			}
		}
		if ( $ipnum & ( 1 << $depth ) ) {
			if ( $x[1] >= $this->databaseSegments ) {
				return $x[1];
			}

			$offset = $x[1];
		} else {
			if ( $x[0] >= $this->databaseSegments ) {
				return $x[0];
			}

			$offset = $x[0];
		}
	}

	$this->log( 'GeoIP API: Error traversing database - perhaps it is corrupt?', 'error' );

	return false;
}