ip2country_test.module in IP-based Determination of a Visitor's Country 7
Determination of user's Country based on IP.
This module uses the IP Address that a user is connected from to deduce the Country where the user is located. This method is not foolproof, because a user may connect through an anonymizing proxy, or may be in an unusual case, such as getting service from a neighboring country, or using an IP block leased from a company in another country. Additionally, users accessing a server on a local network may be using an IP that is not assigned to any country (e.g. 192.168.x.x).
@author Tim Rohaly. <http://drupal.org/user/202830>
File
tests/ip2country_test.moduleView source
<?php
/**
* @file
* Determination of user's Country based on IP.
*
* This module uses the IP Address that a user is connected from to deduce
* the Country where the user is located. This method is not foolproof,
* because a user may connect through an anonymizing proxy, or may be in
* an unusual case, such as getting service from a neighboring country,
* or using an IP block leased from a company in another country.
* Additionally, users accessing a server on a local network may be using
* an IP that is not assigned to any country (e.g. 192.168.x.x).
*
* @author Tim Rohaly. <http://drupal.org/user/202830>
*/
// Utility functions for loading IP/Country DB from external sources.
module_load_include('inc', 'ip2country');
/**
* Implements hook_ip2country_alter().
*/
function ip2country_test_ip2country_alter($path, $arg) {
drupal_set_message('hook_ip2country_alter() executed.');
// @todo Actually do something here!
// Should have a little testing database of IP addresses,
// replace the array in ip2country.test,
// mini DB can be used in place of real DB for testing, plus
// it validates hook.
}
/**
* Implements hook_menu().
*/
function ip2country_test_menu() {
$items = array();
$items['admin/config/location/ip2country'] = array(
'title' => 'IP to Country settings',
'description' => 'Configure the IP/Country settings',
'access arguments' => array(
'administer ip2country',
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'ip2country_admin_settings',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'ip2country.admin.inc',
);
$items['admin/config/location/ip2country/update'] = array(
'title' => 'Update database',
'access arguments' => array(
'administer ip2country',
),
'page callback' => '_ip2country_update',
'type' => MENU_CALLBACK,
'file' => 'ip2country.admin.inc',
);
$items['admin/config/location/ip2country/lookup'] = array(
'title' => 'Lookup IP address in database',
'access arguments' => array(
'administer ip2country',
),
'page callback' => '_ip2country_lookup',
'type' => MENU_CALLBACK,
'file' => 'ip2country.admin.inc',
);
return $items;
}
Functions
Name | Description |
---|---|
ip2country_test_ip2country_alter | Implements hook_ip2country_alter(). |
ip2country_test_menu | Implements hook_menu(). |