You are here

function _ip2country_lookup in IP-based Determination of a Visitor's Country 7

Same name and namespace in other branches
  1. 5 uc_ip2country.module \_ip2country_lookup()
  2. 6 ip2country.admin.inc \_ip2country_lookup()

AJAX callback to lookup an IP address in the database.

Parameters

string $arg: String with IP address.

Return value

string JSON object for display by jQuery script.

2 string references to '_ip2country_lookup'
ip2country_menu in ./ip2country.module
Implements hook_menu().
ip2country_test_menu in tests/ip2country_test.module
Implements hook_menu().

File

./ip2country.admin.inc, line 86
Determination of user's Country based on IP address.

Code

function _ip2country_lookup($arg) {

  // Return results of manual lookup.
  $country_code = ip2country_get_country($arg);
  if ($country_code) {
    $country_list = country_get_list();
    $country_name = $country_list[$country_code];
    print drupal_json_encode(array(
      'message' => t('IP Address @ip is assigned to @country (@code).', array(
        '@ip' => $arg,
        '@country' => $country_name,
        '@code' => $country_code,
      )),
    ));
  }
  else {
    print drupal_json_encode(array(
      'message' => t('IP Address @ip is not assigned to a country.', array(
        '@ip' => $arg,
      )),
    ));
  }
  exit;
}