Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

ip2location_api

2 sites No security coverage
View on drupal.org

A light weight wrapper that provides a Drupal Service interface to the IP2Location API

Features

This module provides a service that wraps the IP2Location api via the PHP library ip2location/ip2location-io-php - currently only Geolocation is implemented. There are two helper functions to return the country code and country name.

Post-Installation

  1. Set up an API key at https://www.ip2location.com
  2. Save the key at admin/config/system/keys/add as Key Type "IP2 Location API Key"
  3. Select the key at admin/config/system/ip2location-settings

After these steps you have access to a Drupal Service in code. The service provides the ability to Geolocate the current request, or specify an IP address to Geolocate.

Additional Requirements

You will need to sign up to IP2Location and get an api key.
Keys are managed using Drupal module Key.

You will need to write custom code to take advantage of this module.

Similar projects

There is an existing project ip2location however this doesn't currently use the API instead it requires on the user downloading the required databases and keeping these up to date.

Community Documentation

Example code:
Assuming you inject this service and saved it as $ip2LocationAPI then
$countryName = $this->ip2LocationAPI->getCountryName();
would get you the country name of the user making the request as processed by the ip2LocationAPI.

Note there is currently no caching of responses beyond a very simple storage on the service itself. Ideally we'd cache response data so we wouldn't make repeated attempts to look up the same IP address.

Activity

Total releases
2
First release
Jul 2025
Latest release
9 months ago
Release cadence
0 days
Stability
0% stable

Releases

Version Type Release date
1.0.0-alpha1 Pre-release Jul 10, 2025
1.0.x-dev Dev Jul 10, 2025