You are here

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

Same filename and directory in other branches
  1. 8 README.txt
  2. 6 README.txt
  3. 7 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 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 5.7+ (Drupal 6 not allowed), Ubercart 1.0 or above.

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

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

NOTE!  When uc_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 several minutes, 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/user/access.

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/settings/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/getting-started/5/install/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.

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.

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

  $ip = $_SERVER['REMOTE_ADDR'];
  $country_code = uc_ip2country_get_country($ip);


The database used 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-authoritive 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/settings/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/settings/ip2country.  Note this can take 2-5 minutes to complete -
do not interrupt the update process or the database will be incomplete and
you'll have to do it again.



Requirements
============
This module is known to work with Drupal 5.x and all Ubercart releases greater
than 1.0 RC5.  While it may run in older versions, I won't promise anything.
Future version of this module WILL be backwards compatible with this initial
release.



Limitations
===========
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/logs/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/settings/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 country code in the Drupal $user object, but otherwise
  6. has no effect on the operation of your site. The intent is simply to provide
  7. the information for use by other modules. Anonymous users are not identified
  8. by country.
  9. Installation
  10. ============
  11. Check requirements: PHP 5 with cURL support enabled.
  12. Drupal 5.7+ (Drupal 6 not allowed), Ubercart 1.0 or above.
  13. Copy ip2country.tar.gz into your sites/all/modules directory and unzip/untar it.
  14. In your web browser, navigate to admin/build/modules and enable the following
  15. module: IP-based determination of Country
  16. NOTE! When uc_ip2country is installed, it downloads a large amount of
  17. data off the Internet to build a table in your Drupal database. This
  18. process can take several minutes, so please be patient and WAIT until
  19. the page loads! You can verify a correct install by looking into your
  20. Drupal database for the ip2country table and verifying that it is full
  21. of data.
  22. This module defines an "administer ip2country" permission, which must be
  23. explicitly enabled for the administration user at admin/user/access.
  24. You must now enter values in the administration menus. Defaults are chosen
  25. reasonably, but you should examine them and set them as you wish.
  26. Go to admin/settings/ip2country to review and change settings for the
  27. IP-based determination of Country module. You can read about the Debug
  28. preferences in the "Troubleshooting" section below.
  29. Finally, cron needs to be running for automatic database updates. If you
  30. haven't set up cron for your Drupal site, refer to
  31. http://drupal.org/getting-started/5/install/cron for instructions.
  32. Because the database update takes so long to run, you may have to increase
  33. the allowed cron run time. This requires editing includes/common.inc and
  34. changing the time in the function drupal_cron_run() from 240 to 10*60.
  35. Everything should now work. If it doesn't, read the rest of this document
  36. (which you really should have done first, anyway!). If you still have
  37. problems see the "Troubleshooting" section below.
  38. Features
  39. ========
  40. This module uses the IP Address that a user is connected from to deduce the
  41. Country where the user is located. This method is not foolproof, because
  42. a user may connect through an anonymizing proxy, or may be in an unusual
  43. situation, such as using an ISP from a neighboring country, or using an
  44. IP block leased from a company in another country. Additionally, users
  45. accessing a server on a local network may be using an IP that is not assigned
  46. to any country (e.g. 192.168.1.x or 127.0.0.1).
  47. Country determination occurs upon user login. If a country can be determined
  48. from the IP address, the ISO 3166 2-character country code is stored in the
  49. Drupal $user object as $user->country_iso_code_2. If no country can be
  50. determined, this member variable is left unset.
  51. Alternatively, a function is provides so that you may look up the country
  52. from within your own code, for your own use. The way to use this is:
  53. $ip = $_SERVER['REMOTE_ADDR'];
  54. $country_code = uc_ip2country_get_country($ip);
  55. The database used is maintained by ARIN, the American Registry for Internet
  56. Numbers (http://www.arin.net/about_us/index.html), which is one of the five
  57. official Regional Internet Registries (RIR) responsible for assigning IP
  58. addresses. The claim is the database is 98% accurate, with most of the
  59. problems coming from users in less-developed countries. Regardless, there's
  60. no more-authoritive source of this information. Although the default RIR used
  61. is ARIN, an admin menu allows you to choose any of the five.
  62. If you have cron set up for your Drupal site, this IP to Country database will
  63. be automatically updated at a frequency determined by the admin menu at
  64. admin/settings/ip2country. A checkbox is provided to turn on/off
  65. logging of database updates. The default update frequency is 1 week, but it
  66. can be adjusted from 1 day up to 4 weeks. Because of the time it takes to
  67. update and because the database is very stable, shorter database update times
  68. are not needed.
  69. Database updates may also be performed manually by pressing the button at
  70. admin/settings/ip2country. Note this can take 2-5 minutes to complete -
  71. do not interrupt the update process or the database will be incomplete and
  72. you'll have to do it again.
  73. Requirements
  74. ============
  75. This module is known to work with Drupal 5.x and all Ubercart releases greater
  76. than 1.0 RC5. While it may run in older versions, I won't promise anything.
  77. Future version of this module WILL be backwards compatible with this initial
  78. release.
  79. Limitations
  80. ===========
  81. Because the database update takes so long to run, you may have to increase
  82. the allowed cron run time. This requires editing includes/common.inc and
  83. changing the time in the function drupal_cron_run() from 240 to 10*60.
  84. Troubleshooting
  85. ===============
  86. Does your site have PHP 5 built with cURL support? Execute
  87. or visit admin/logs/status/php to see the details of your PHP installation.
  88. Because it's not practical to log in from another country in order to test
  89. these features, a debugging setting is provided to allow the administrator
  90. to specify a Country or IP Address to simulate. When debugging is enabled,
  91. it only affects the country stored in the administrator's $user object.
  92. To use this debugging setting, check the box "Admin Debug" at
  93. admin/settings/ip2country. You must also specify either a Country to simulate
  94. or an IP to simulate. A notification will be printed across the top of the
  95. page when you submit the form, letting you know that the debug feature has
  96. successfully been turned on (or off). The simulated Country or IP will be
  97. used for the administrator until this feature is turned off in the admin menu.
  98. When all else fails, read the comments in the code - there are some debugging
  99. print statements left in that can be uncommented to see what is going on, and
  100. most functions are described in the comments.