You are here

README.txt in IP-based Determination of a Visitor's Country 7

Same filename and directory in other branches
  1. 8 README.txt
  2. 5 README.txt
  3. 6 README.txt
About
=====
This module uses a visitor's IP address to identify the geographical location
(country) of the user.  The module makes this determination and stores the
result as an ISO 3166-1 2-character country code in the Drupal $user object,
but otherwise has no effect on the operation of your site.  The intent is
simply to provide the information for use by other modules.  Anonymous users
are not identified by country.


Installation
============
Check requirements:  PHP 5 with cURL support enabled.  Drupal 7.x.

Copy ip2country.tar.gz into your sites/all/modules directory and unzip/untar it.

In your web browser, navigate to admin/modules and enable the following
module: IP-based determination of Country

NOTE!  When ip2country is installed, it downloads a large amount of
data off the Internet to build a table in your Drupal database.  This
process can take up to 30 seconds, so please be patient and WAIT until
the page loads!  You can verify a correct install by looking into your
Drupal database for the ip2country table and verifying that it is full
of data.

This module defines an "administer ip2country" permission, which must be
explicitly enabled for the administration user at admin/people/permissions.

You must now enter values in the administration menus.  Defaults are chosen
reasonably, but you should examine them and set them as you wish.

Go to admin/config/people/ip2country to review and change settings for the
IP-based determination of Country module.  You can read about the Debug
preferences in the "Troubleshooting" section below.

Finally, cron needs to be running for automatic database updates.  If you
haven't set up cron for your Drupal site, refer to
http://drupal.org/documentation/install/after/cron for instructions.

Because the database update takes so long to run, you may have to increase
the allowed cron run time.  This requires editing includes/common.inc and
changing the time in the function drupal_cron_run() from 240 to 10*60.  This
function can be found in includes/common.inc under your Drupal root.  Look
for the first occurrence of set_time_limit() in this function and replace
the argument with 600.

Everything should now work.  If it doesn't, read the rest of this document
(which you really should have done first, anyway!).  If you still have
problems see the "Troubleshooting" section below.


Features
========
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
situation, such as using an ISP 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.1.x or 127.0.0.1).

Country determination occurs upon user login.  If a country can be determined
from the IP address, the ISO 3166 2-character country code is stored in the
Drupal $user object as $user->country_iso_code_2.  If no country can be
determined, this member variable is left unset.

Rules support allows you to detect the user's country and take action
depending on the value. For instance, you could have customized landing pages
for users from different countries, or show/hide content based on the user's
country (e.g. a product not available for sale in a certain country).

Alternatively, a function is provided so that you may look up the country
from within your own code, for your own use.  The way to use this is:

  $ip = ip_address();
  $country_code = ip2country_get_country($ip);

Drupal core provides a function which can transform this $country_code into
a country name.  Use it like this:

  include_once DRUPAL_ROOT . '/includes/locale.inc';

  $country_list = country_get_list();
  $country_name = $country_list[$country_code];


The database used by this module is maintained by ARIN, the American Registry
for Internet Numbers (http://www.arin.net/about_us/index.html), which is one of
the five official Regional Internet Registries (RIR) responsible for assigning
IP addresses.  The claim is the database is 98% accurate, with most of the
problems coming from users in less-developed countries.  Regardless, there's
no more-authoritative source of this information.  Although the default RIR
used is ARIN, an admin menu allows you to choose any of the five.

If you have cron set up for your Drupal site, this IP to Country database will
be automatically updated at a frequency determined by the admin menu at
admin/config/people/ip2country.  A checkbox is provided to turn on/off
logging of database updates.  The default update frequency is 1 week, but it
can be adjusted from 1 day up to 4 weeks.  Because of the time it takes to
update and because the database is very stable, shorter database update times
are not needed.

Database updates may also be performed manually by pressing the button at
admin/config/people/ip2country.  Note this can take up to 30 seconds to
complete - do not interrupt the update process or the update will fail and you
will have to do it again.  (A failed update does *not* corrupt the database.)


Drush support
=============
This module provides three commands for drush:

  drush ip2country-update --registry=<registry>
      Updates the ip2country database from the specified registry, or from
      the default registry if not specified.

  drush ip2country-lookup <ip>
      Looks up the given IP address in the ip2country database displays the
      country associated with that IP address.

  drush ip2country-status
      Prints the time and data source (RIR) of the last database update.

Drush may also be used to configure any of the settings for this program.  For
example, to see all the settings, use:

  drush vget ip2country

And to change the settings, use the corresponding drush vset.  For example, to
disable automatic database updates, use:

  drush vset ip2country_update_interval 0

Or to turn on debug country/IP spoofing, use:

  drush vset ip2country_debug 1

More help may be found using drush help --filter=ip2country


Requirements
============
This module is tested to work with Drupal 7.x.  There is a separate version
specifically for Drupal 6.x (and one for Drupal 5.x too, if you still need
that).  Future version of this module will be backwards compatible with this
release.


Limitations
===========
    [ Note for the Drupal 7.x version - I haven't verified that this
      information is still true for the D7 release. ]

Because the database update takes so long to run, you may have to increase
the allowed cron run time.  This requires editing includes/common.inc and
changing the time in the function drupal_cron_run() from 240 to 10*60.


Troubleshooting
===============
Does your site have PHP 5 built with cURL support?  Execute <?php phpinfo();?>
or visit admin/reports/status/php to see the details of your PHP installation.

Because it's not practical to log in from another country in order to test
these features, a debugging setting is provided to allow the administrator
to specify a Country or IP Address to simulate.  When debugging is enabled,
it only affects the country stored in the administrator's $user object.
To use this debugging setting, check the box "Admin Debug" at
admin/config/people/ip2country.  You must also specify either a Country to
simulate or an IP to simulate.  A notification will be printed across the top
of the page when you submit the form, letting you know that the debug feature
has successfully been turned on (or off).  The simulated Country or IP will be
used for the administrator until this feature is turned off in the admin menu.

When all else fails, read the comments in the code - there are some debugging
print statements left in that can be uncommented to see what is going on, and
most functions are described in the comments.

File

README.txt
View source
  1. About
  2. =====
  3. This module uses a visitor's IP address to identify the geographical location
  4. (country) of the user. The module makes this determination and stores the
  5. result as an ISO 3166-1 2-character country code in the Drupal $user object,
  6. but otherwise has no effect on the operation of your site. The intent is
  7. simply to provide the information for use by other modules. Anonymous users
  8. are not identified by country.
  9. Installation
  10. ============
  11. Check requirements: PHP 5 with cURL support enabled. Drupal 7.x.
  12. Copy ip2country.tar.gz into your sites/all/modules directory and unzip/untar it.
  13. In your web browser, navigate to admin/modules and enable the following
  14. module: IP-based determination of Country
  15. NOTE! When ip2country is installed, it downloads a large amount of
  16. data off the Internet to build a table in your Drupal database. This
  17. process can take up to 30 seconds, so please be patient and WAIT until
  18. the page loads! You can verify a correct install by looking into your
  19. Drupal database for the ip2country table and verifying that it is full
  20. of data.
  21. This module defines an "administer ip2country" permission, which must be
  22. explicitly enabled for the administration user at admin/people/permissions.
  23. You must now enter values in the administration menus. Defaults are chosen
  24. reasonably, but you should examine them and set them as you wish.
  25. Go to admin/config/people/ip2country to review and change settings for the
  26. IP-based determination of Country module. You can read about the Debug
  27. preferences in the "Troubleshooting" section below.
  28. Finally, cron needs to be running for automatic database updates. If you
  29. haven't set up cron for your Drupal site, refer to
  30. http://drupal.org/documentation/install/after/cron for instructions.
  31. Because the database update takes so long to run, you may have to increase
  32. the allowed cron run time. This requires editing includes/common.inc and
  33. changing the time in the function drupal_cron_run() from 240 to 10*60. This
  34. function can be found in includes/common.inc under your Drupal root. Look
  35. for the first occurrence of set_time_limit() in this function and replace
  36. the argument with 600.
  37. Everything should now work. If it doesn't, read the rest of this document
  38. (which you really should have done first, anyway!). If you still have
  39. problems see the "Troubleshooting" section below.
  40. Features
  41. ========
  42. This module uses the IP Address that a user is connected from to deduce the
  43. Country where the user is located. This method is not foolproof, because
  44. a user may connect through an anonymizing proxy, or may be in an unusual
  45. situation, such as using an ISP from a neighboring country, or using an
  46. IP block leased from a company in another country. Additionally, users
  47. accessing a server on a local network may be using an IP that is not assigned
  48. to any country (e.g. 192.168.1.x or 127.0.0.1).
  49. Country determination occurs upon user login. If a country can be determined
  50. from the IP address, the ISO 3166 2-character country code is stored in the
  51. Drupal $user object as $user->country_iso_code_2. If no country can be
  52. determined, this member variable is left unset.
  53. Rules support allows you to detect the user's country and take action
  54. depending on the value. For instance, you could have customized landing pages
  55. for users from different countries, or show/hide content based on the user's
  56. country (e.g. a product not available for sale in a certain country).
  57. Alternatively, a function is provided so that you may look up the country
  58. from within your own code, for your own use. The way to use this is:
  59. $ip = ip_address();
  60. $country_code = ip2country_get_country($ip);
  61. Drupal core provides a function which can transform this $country_code into
  62. a country name. Use it like this:
  63. include_once DRUPAL_ROOT . '/includes/locale.inc';
  64. $country_list = country_get_list();
  65. $country_name = $country_list[$country_code];
  66. The database used by this module is maintained by ARIN, the American Registry
  67. for Internet Numbers (http://www.arin.net/about_us/index.html), which is one of
  68. the five official Regional Internet Registries (RIR) responsible for assigning
  69. IP addresses. The claim is the database is 98% accurate, with most of the
  70. problems coming from users in less-developed countries. Regardless, there's
  71. no more-authoritative source of this information. Although the default RIR
  72. used is ARIN, an admin menu allows you to choose any of the five.
  73. If you have cron set up for your Drupal site, this IP to Country database will
  74. be automatically updated at a frequency determined by the admin menu at
  75. admin/config/people/ip2country. A checkbox is provided to turn on/off
  76. logging of database updates. The default update frequency is 1 week, but it
  77. can be adjusted from 1 day up to 4 weeks. Because of the time it takes to
  78. update and because the database is very stable, shorter database update times
  79. are not needed.
  80. Database updates may also be performed manually by pressing the button at
  81. admin/config/people/ip2country. Note this can take up to 30 seconds to
  82. complete - do not interrupt the update process or the update will fail and you
  83. will have to do it again. (A failed update does *not* corrupt the database.)
  84. Drush support
  85. =============
  86. This module provides three commands for drush:
  87. drush ip2country-update --registry=
  88. Updates the ip2country database from the specified registry, or from
  89. the default registry if not specified.
  90. drush ip2country-lookup
  91. Looks up the given IP address in the ip2country database displays the
  92. country associated with that IP address.
  93. drush ip2country-status
  94. Prints the time and data source (RIR) of the last database update.
  95. Drush may also be used to configure any of the settings for this program. For
  96. example, to see all the settings, use:
  97. drush vget ip2country
  98. And to change the settings, use the corresponding drush vset. For example, to
  99. disable automatic database updates, use:
  100. drush vset ip2country_update_interval 0
  101. Or to turn on debug country/IP spoofing, use:
  102. drush vset ip2country_debug 1
  103. More help may be found using drush help --filter=ip2country
  104. Requirements
  105. ============
  106. This module is tested to work with Drupal 7.x. There is a separate version
  107. specifically for Drupal 6.x (and one for Drupal 5.x too, if you still need
  108. that). Future version of this module will be backwards compatible with this
  109. release.
  110. Limitations
  111. ===========
  112. [ Note for the Drupal 7.x version - I haven't verified that this
  113. information is still true for the D7 release. ]
  114. Because the database update takes so long to run, you may have to increase
  115. the allowed cron run time. This requires editing includes/common.inc and
  116. changing the time in the function drupal_cron_run() from 240 to 10*60.
  117. Troubleshooting
  118. ===============
  119. Does your site have PHP 5 built with cURL support? Execute
  120. or visit admin/reports/status/php to see the details of your PHP installation.
  121. Because it's not practical to log in from another country in order to test
  122. these features, a debugging setting is provided to allow the administrator
  123. to specify a Country or IP Address to simulate. When debugging is enabled,
  124. it only affects the country stored in the administrator's $user object.
  125. To use this debugging setting, check the box "Admin Debug" at
  126. admin/config/people/ip2country. You must also specify either a Country to
  127. simulate or an IP to simulate. A notification will be printed across the top
  128. of the page when you submit the form, letting you know that the debug feature
  129. has successfully been turned on (or off). The simulated Country or IP will be
  130. used for the administrator until this feature is turned off in the admin menu.
  131. When all else fails, read the comments in the code - there are some debugging
  132. print statements left in that can be uncommented to see what is going on, and
  133. most functions are described in the comments.