Smart IP identify visitor's geographical location (longitude/latitude), country, region, city and postal code based on the IP address of the user. These information will be stored in session variable ($_SESSION) with array key 'smart_ip', Drupal $user->data object with array key 'geoip_location' in Drupal 6 and 7 and user data service using the parameters 'smart_ip' as module and 'geoip_location' as name in Drupal 8 of the user but optionally it can be disabled (by role) at Smart IP settings page. Other modules can use the function smart_ip_get_location($ip_address) in Drupal 6 and 7 and \Drupal\smart_ip\SmartIp::query($ipAddress) in Drupal 8 that returns an array containing the visitor's ISO 3166 2-character country code, longitude, latitude, region (FIPS), city and postal code. It provides a feature for you to perform your own IP lookup and admin spoofing of an arbitrary IP for testing purposes.

Check out these demo sites:


  • Ten data source options available: local database with data from parsed MaxMind CSV (For Drupal 6 and 7 only), paid MaxMind GeoIP Legacy Web Services (For Drupal 6 and 7 only), paid MaxMind GeoIP2 Precision Web Services, MaxMind GeoIP Legacy binary file database (thanks to jbulcher. For Drupal 6 and 7 only), MaxMind GeoIP2 binary database, MaxMind's Apache module mod_geoip, IP2Location binary database, IPInfoDB.com web service, X-GeoIP-Country: XX header (thanks to jp.stacey) and Cloudflare IP Geolocation.
  • Maxmind's Apache module mod_geoip, Cloudflare IP Geolocation and X-GeoIP-Country as fallback for the current visitor's geolocation info if the data source of Smart IP returns empty.
  • IPV4 and IPV6 support by the following Smart IP data sources: MaxMind GeoIP Legacy Web Services, GeoIP2 Precision Web Services, MaxMind GeoIP2 binary database, IP2Location binary database and IPInfoDB.com web service.
  • Monthly auto-update of MaxMind CSV database format file for local database source.
  • Weekly auto-update of MaxMind GeoIP Legacy and MaxMind GeoIP2 binary database format file for licensed version.
  • Monthly auto-update of MaxMind GeoIP Legacy and MaxMind GeoIP2 binary database format file for lite version.
  • Visitor’s geolocation block available (Device Geolocation module).
  • Geolocate users by role (see details: https://drupal.org/node/990546).
  • Update users' geolocation info based on defined time interval (at "Frequency of user's geolocation checking" field). Useful to get the updated users' geolocation even they moved from one place to another.
  • Geolocate users to specific pages (see details: https://drupal.org/node/1069440) and with timeout that will prompt users for geolocation (see details: https://drupal.org/node/1061264).
  • User's geolocation update using AJAX, useful for webpages or sites that are cached
  • Hide/show a Block based on visitor's country via Block condition settings (For Drupal 8 only)
  • Token support (For Drupal 7 only. Thanks to bgilhome).
  • Geolocation Historical Data Records (For Drupal 6 only and still in progess see https://drupal.org/node/1027158).
  • Exposes Smart IP visitor's location details to Views field (coordinates, country, ISO 3166 2-character country code, region, region code (FIPS), city and zip. For Drupal 6 and 7 only.), Views filter (country, ISO 3166 2-character country code, region, region code (FIPS), city and zip. For Drupal 6 and 7 only) and Views region/country (ISO 3166 2-character country code) filter/contextual filter (For Drupal 7 only) sponsored by Sohal Khatwani.
  • Integration with Openlayers Proximity via Views field, filter and sort (See details: https://drupal.org/node/1207582 - Drupal 6 sponsored by nyleve101 and port to Drupal 7 sponsored by loera8000).
  • Supports views queries from Search API (For Drupal 7 only).
  • Integration with Rules module. (For Drupal 7 only. Thanks to klausi).
  • Supports Session Cache API.
  • Maxmind GeoIP Web Services, available for Country Web Service (Thanks to echataig), City/ISP/Organization Web Service (Thanks to namli and duntuk) and Insights (formerly Omni) Web Service.
  • Smart IP with a Maxmind GeoIP City Database from a paid account read steps (documented by jbulcher).

Data Sources

  1. MaxMind's database is the source of Smart IP database that makes the association between IP address and geographical location (longitude/latitude), region, city and postal code. It can be found at http://www.maxmind.com/app/geolitecountry it has two versions: a very accurate and up to date payable version and a not quite accurate free lite version. Smart IP downloads and process the CSV files (GeoLiteCity-Location.csv and GeoLiteCity-Blocks.csv) to store to Smart IP database. An optional once a month (MaxMind updates its database every first day of a month) automatic update of the Smart IP database is provided or it can be manually updated at Smart IP admin page. The database of Maxmind is very huge, the two CSV files size is about 150MB and the size when stored to SQL database is about 450MB with almost 5 million rows and about 600MB additional database space for temporary working table for Smart IP database update. The process of downloading the archived CSV files from Maxmind's server, extracting the downloaded zip file, parsing the CSV files and storing to the database will took more or less eight hours (depends on server's speed). It uses the batch system process. If interrupted by an unexpected error, it can recover from where it stopped or the administrator can manually continue the broken process at Smart IP admin page.
  2. MaxMind GeoIP Legacy binary format database. Smart IP supported paid and lite versions. Paid version needs license key purchased from maxmind.com. MaxMind GeoIP Legacy's binary database uses "a custom binary format to maximize lookup speed", made accessible via their custom API. The binary database is roughly 40MB, and will be downloaded and extracted automatically at Smart IP admin page. It has two options: manual and weekly (licensed version) / monthly (lite version) automatic update of binary database. MaxMind updates the database every Tuesday and Smart IP automatically download every Wednesday for licensed version and every first Wednesday of the month for lite version (if automatic update is selected). In manual update option, the binary file must be downloaded here (for licensed version) and for lite version MaxMind binary file can be downloaded here. The downloaded binary (.dat) file must be uploaded manually to your server.
  3. MaxMind GeoIP2 binary database. It is the evolution of MaxMind's original GeoIP binary database or now called GeoIP Legacy. This MaxMind's binary database uses a custom binary format to maximize lookup speed and accessible via two available APIs: MaxMind DB Reader PHP API which includes an optional C extension that you may install to dramatically increase the performance of lookups in GeoIP2 binary database and the default GeoIP2 PHP API. Lite version binary database can be downloaded here. For licensed version, you will need to enter your license below and the binary database file can be downloaded here (you will need to login to your MaxMind account first). The binary database is roughly 130MB, and there's an option below to enable the automatic download/extraction of it. The downloaded file GeoLite2-City.mmdb (if Lite version City edition) or GeoIP2-City.mmdb (if Licensed version City edition) or GeoLite2-Country.mmdb (if Lite version Country edition) or GeoIP2-Country.mmdb (if Licensed version Country edition) must be uploaded to your server at "smart_ip" labelled folder inside your Drupal private folder or to your defined custom path.
  4. Paid MaxMind GeoIP Legacy Web Services. A license key is required here. You will need to buy one of their services and they will provide you the login details. You can view your license key inside your MaxMind account.
  5. Paid MaxMind GeoIP2 Precision Web Services. A user ID and license key is required here. You will need to buy one of their services and they will provide you the login details. You can view your user ID and license key inside your MaxMind account.
  6. IP2Location binary database. It uses two binary database files; one is for IPV4 address support and the other is for IPV6 address support. You will manually download these two binary database files and upload them to your server. Automatic update is not yet supported here and its your responsibility to update them manually every month. Paid and free versions are available. You need to register first for an account here for lite version and login here in able to download the two binary database files. For licensed version, you need to buy their product and they will provide you the login details and use it to login here. You can download the files here for lite version and here for licensed version. Recommended product ID are DB1 (if you need country level only and more faster query) or DB11 (if you need more details but this is less faster than DB1). Caching such as "Memory cache" and "Shared memory" are available to accelerate lookup speed.
  7. IPInfoDB.com web service which uses IP2Location, in this case IPInfoDB.com will handle database resource load instead of your server's database. You will need an API key to use this and you must be logged in to get it.
  8. MaxMind's Apache module mod_geoip... read more.
  9. X-GeoIP-Country: XX header, set by e.g. nginx via $_SERVER['HTTP_X_GEOIP_COUNTRY'] variable.
  10. Cloudflare IP Geolocation: your website must be using Cloudflare CDN and "IP Geolocation" option must be enabled at your Cloudflare settings. Cloudflare adds CF_IPCountry header to all requests to your site, accessed via $_SERVER['HTTP_CF_IPCOUNTRY'] variable.


  • PHP 5.4 and up
  • geoip2/geoip2 library (if using MaxMind as data source. Setup instructions)
  • ip2location/ip2location-php library (if using IP2Location as data source. Setup instructions)
  • Device Geolocation (for more detailed visitor's geolocation using client device as location source)
  • Session Cache API (for sites that uses caching engine or web accelerator like Varnish)


  1. Copy the extracted smart_ip directory to your Drupal sites/all/modules directory.
  2. Login as an administrator. Enable the module at http://www.example.com/?q=admin/modules
  3. Set your private file system path at http://www.example.com/?q=admin/config/media/file-system
  4. Configure/update Smart IP database/lookup an IP at http://www.example.com/?q=admin/config/people/smart_ip. For details about the Smart IP settings, please check this.
  5. If your server is using reverse proxy (like Varnish or nginx), please add the followings codes to your settings.php:
      // Tell Drupal that we are behind a reverse proxy server
      $conf['reverse_proxy'] = TRUE;
      // List of trusted IPs (IP numbers of our reverse proxies)
      $conf['reverse_proxy_addresses'] = array(
  6. For Drupal multi sites, the Smart IP module of each can be setup to lookup to one GeoIP database path. Check this article for instructions: Using GeoIPLookup CLI tool's GeoIP database as Smart IP's data source.

Note: The Smart IP database is empty upon initial installation of this module. Either manually update the Smart IP database at admin page or wait for the cron to run and update Smart IP database automatically for you.

Configuration / Cache Performance Note

Be aware that this module adds location data to the session of any roles you choose to geolocate. If you enable geolocation for anonymous users, all of your visitors will bypass the page cache.

If you wish to display geotargted content to anonymous users, while still maintaining the page cache for your general content, consider the Ajax Blocks project, paired with a custom block that fires off the geolocation code directly.

Session get and set functions

As support for Session Cache API, Smart IP implemented get and set functions accessing storage of visitor's geographical location. For developers, we are strongly suggest to use these get and set functions in your codes. Below are the sample codes usage.


Using direct $_SESSION variable:

    if ($_SESSION['smart_ip']['location']['country_code'] == 'PH') {
      drupal_set_message(t('You are in the Philippines.'), 'status');

Using smart_ip_session_get() function (Recommended for Drupal 6 and 7 only):

    $smart_ip_session = smart_ip_session_get('smart_ip');
    if ($smart_ip_session['location']['country_code'] == 'PH') {
      drupal_set_message(t('You are in the Philippines.'), 'status');

Using \Drupal\smart_ip\SmartIpLocation service container (Recommended for Drupal 8 only):

    /** @var \Drupal\smart_ip\SmartIpLocation $location */
    $location = \Drupal::service('smart_ip.smart_ip_location');
    if ($location->get('countryCode') == 'PH') {
      drupal_set_message(t('You are in the Philippines.'), 'status');

Using direct $_SESSION variable:

    if ($_SESSION['smart_ip']['location']['country_code'] == 'UK') {
      $_SESSION['smart_ip']['location']['country_code'] = 'GB';

Using smart_ip_session_set() function (Recommended for Drupal 6 and 7 only):

    $smart_ip_session = smart_ip_session_get('smart_ip');
    if ($smart_ip_session['location']['country_code'] == 'UK') {
      $smart_ip_session['location']['country_code'] = 'GB';
      smart_ip_session_set('smart_ip', $smart_ip_session);

Using \Drupal\smart_ip\SmartIpLocation service container (Recommended for Drupal 8 only):

    /** @var \Drupal\smart_ip\SmartIpLocation $location */
    $location = \Drupal::service('smart_ip.smart_ip_location');
    if ($location->get('countryCode') == 'UK') {
      $location->set('countryCode', 'GB')

Modules that uses Smart IP:

Geolocate Logs
Provides geographical location for Drupal log event's hostname (Recent log messages and Recent hits) and whois lookup for hostname using any free external site offering whois service. read more...
Webform Smart IP

This project creates a new Webform field type called 'smart_ip' that uses the Smart IP module to provide additional data about the form submitter in hidden fields. The data will show up on the Results/Submissions admin pages, but will be hidden on the form submission. read more...

EU Cookie Compliance
This module intends to deal with the EU Directive on Privacy and Electronic Communications that comes into effect in the UK on 26th May 2012. read more...

This module uses METAR (METeorological Aerodrome Report) data to display current weather conditions from anywhere in the world. read more...

Weather block

The module provides support for Yahoo Weather, World Weather Online and weather.com weather forecasts. read more...

IP Geolocation Views and maps
  1. a Views mapping engine, combined with
  2. a set of visitor location retrieval technologies based on HTML5 (GPS) and/or IP address lookups. read more...
Get Locations

Provide Google maps API version 3 enabled maps on which to display markers of locations found in location-enabled content-types.

These can be displayed per node, eg "/getlocations/node/xxx" will display all the locations associated with that node. They can also be displayed per content-type, so if your content-type has a machine name 'venue' you can show them all with "/getlocations/type/venue". read more...

Mapstraction CCK IP

This sub-module of Mapstraction CCK provides the integration between the Smart IP module and Mapstraction CCK, allowing to center maps or include geotags in the web user location, retrieved from his IP. read more...

IP to Locale
Provides IP lookup and redirection services for Drupal sites. read more...
IP Geolocation Views & Maps
The module makes it very easy to create Views-based mapping solutions using the map renderer of your choice (Google, OpenLayers2 or Leaflet) with any location storage module of your choice, e.g. Get Locations, Geofield, Geolocation Field or Location. read more...
IP Block
Block user access based on their IP address.
Country Access
Country access module provides the ability to add a list of countries that you wish to allow or deny access your site. read more...
A Drupal module displaying Islamic prayer times in a block. read more...


Smart IP is being developed by Roland Michael dela Peña (arpeggio) of webfoobar. The author may be contacted if interested in sponsoring a new feature of this module or related module, Drupal consultation/installation/optimization or other Drupal-related projects.

Get involve

If you find this module useful, please consider the following:

  • Helping other users that request for a support by sharing what you know is a kind thing to do.
  • Patches are welcome. If you are developer, help fix reported bugs by sharing patches.
  • Want to help but don't have the time, giving donation would help me allocate more time to support new feature request and fix old bugs (Donate here).

Your support is much appreciated. Thank you in advance.

Device Geolocation

Device Geolocation is integrated into this module which gives more detailed visitor's geolocation using client device location source that implements HTML5 or W3C Geolocation API whereas the coordinates are geocoded using Google Geocoding service. More datails...

Practical applications

Project information