Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Varbase FAQs 9.2.1 Minor update available for module varbase_faqs (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

IP 2 Location API

1 sites No security coverage
View on drupal.org

This module provides a Drupal service to interact with the IP2Location API, allowing you to geolocate IP addresses to retrieve country codes and names. It wraps the official IP2Location PHP library and requires an API key to function.

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
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

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