Ivan Zugec

Drupal Consultant

How to use GeoIP & Context GeoIP module

Using the GeoIP module with Context GeoIP module, it makes it really easy to create a context which has a specific condition to only display a block if your IP location is from a particular country.

Furthermore GeoIP has a powerful API to pull out location information.

In this article I’ll show you how to setup GeoIP and Context GeoIP module.

Getting started

A few modules will need to be downloaded before we start. Download the following modules:

  1. GeoIP
  2. Context GeoIP
  3. Context
  4. Ctools (required by Context)

Once the modules have been downloaded go and enable the GeoIP and Context GeoIP module.

geo_1.png

Configure GeoIP

Once you have enabled GeoIP you’ll have to download the MaxMind database file.

The country binary file can be downloaded from:
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP....

Once you have downloaded the file, uncompress the file and copy it into “sites/all/libraries/geoip”.
To make sure everything is working to go “admin/settings/geoip” and if you get an error, double check and make sure the binary file is in “sites/all/libraries/geoip”.

geo_2.png

Context Geo IP

If you haven't already done so go and enable the Context Geo IP module.
NOTE: Don’t forget to enable Context and Ctools.

geo_3.png

Now go to a context rule and you should see Geo IP in the condition select box.

geo_4.png

And there you have it, now you can create context rules for a specific IP location.

About the author: Ivan Zugec
Ivan Zugec's picture

Ivan is a Sydney Australia based Drupal Developer with over 5 years experience.

Follow:
Version: 

Comments

mikeytown2's picture

Submitted by mikeytown2 on

When doing GeoIP, be aware of page caching and 3rd party share utilities & robots. I like to turn off GeoIP if the user agent ($_SERVER['HTTP_USER_AGENT']) contains the word facebook, googlebot, yahoo, msn, or bing. To take care of caching I set a cookie and then use that cookie value as a cache ID modifier for the page cache (patch for memcache: http://drupal.org/node/942914). The other advantage of the cookie route is you only need to lookup the IP once.

Add new comment