You are here

function uc_ip2country_get_country in IP-based Determination of a Visitor's Country 5

Get the Country Code from the IP address

Return value

FALSE if the lookup failed to find a country for this IP

4 calls to uc_ip2country_get_country()
uc_ip2country_admin_settings in ./uc_ip2country.module
Default IP to Country administration settings.
uc_ip2country_admin_settings_submit in ./uc_ip2country.module
Process Forms submitted by IP to Country administration page
uc_ip2country_user in ./uc_ip2country.module
Implementation of hook_user().
_ip2country_lookup in ./uc_ip2country.module
AJAX callback to lookup an IP address in the database.

File

./uc_ip2country.module, line 393
Determination of user's Country based on IP

Code

function uc_ip2country_get_country($ip_address) {
  $ipl = ip2long($ip_address);
  if (is_long($ip_address)) {
    $ipl = ip_address;
  }

  // Locate IP within ranges
  $sql = "SELECT country FROM {ip2country}\n             WHERE (%d >= `ip_range_first` AND %d <= `ip_range_last`) LIMIT 1";
  $result = db_result(db_query($sql, $ipl, $ipl));
  return $result;
}