You are here

private function Database::readCountryNameAndCode in Smart IP 6.2

Same name and namespace in other branches
  1. 7.2 includes/vendor/ip2location/ip2location-php/IP2Location.php \IP2Location\Database::readCountryNameAndCode()

High level function to fetch the country name and code

@access private

Parameters

int|boolean $pointer Position to read from, if false, return self::INVALID_IP_ADDRESS:

Return value

array

1 call to Database::readCountryNameAndCode()
Database::lookup in includes/vendor/ip2location/ip2location-php/IP2Location.php
This function will look the given IP address up in the database and return the result(s) asked for

File

includes/vendor/ip2location/ip2location-php/IP2Location.php, line 1132

Class

Database
IP2Location database class

Namespace

IP2Location

Code

private function readCountryNameAndCode($pointer) {
  if (false === $pointer) {

    // Deal with invalid IPs
    $countryCode = self::INVALID_IP_ADDRESS;
    $countryName = self::INVALID_IP_ADDRESS;
  }
  elseif (0 === self::$columns[self::COUNTRY_CODE][$this->type]) {

    // If the field is not suported, return accordingly
    $countryCode = self::FIELD_NOT_SUPPORTED;
    $countryName = self::FIELD_NOT_SUPPORTED;
  }
  else {

    // Read the country code and name (the name shares the country's pointer,
    // but it must be artificially displaced 3 bytes ahead: 2 for the country code, one
    // for the country name's length)
    $countryCode = $this
      ->readString($pointer + self::$columns[self::COUNTRY_CODE][$this->type]);
    $countryName = $this
      ->readString($pointer + self::$columns[self::COUNTRY_NAME][$this->type], 3);
  }
  return [
    $countryName,
    $countryCode,
  ];
}