Part of the IP ecosystem · 13 projects
This module integrates with an IP address lookup API to retrieve detailed geolocation information for IP addresses. It allows you to fetch data such as city, country, region, and coordinates, and provides services for easy integration into your Drupal site.
This module helps in integration of IP Address Lookup (https://ipapi.co/#api).
ipapi.co provides a REST API to find the location of an IP address.
Specifically, you can get the following information for any IP address:
city, region (name & code), country (name & code), continent, postal code / zip code, latitude, longitude, timezone, utc offset, european union (EU) membership, country calling code, country capital, country tld (top-level domain), currency (name & code), area & population of the country, languages spoken, asn, organization and hostname*.
When you are using this api on client side, it work perfectly using the public IP.
GET https://ipapi.co/{format}/
Like GET https://ipapi.co/json/
When it comes to use at server side, it start giving response as per server IP
This module helps you in working with client side with some back-end configuration. It provide services which you can easily use in getting IP address details.
Step Involve
- Install module as you do.
- If you have API you can add in the configuration
/admin/config/services/ip_address_lookup - There is also a debug option which you can used to check the response for specifit IP address.
Function to Use
- getCountry() : This will return the Country Name
- getCity() : This will return the City Name
- getCountryCode() : This will return the Country Code
- getRegion() : Get region/state short code (FIPS or ISO)
- getLatitude() : Get latitude
- getLongitude() : Get longitude.
- getPostal() : Get zip/Postal code.
- getTimezone() : Get timezone
How to use service in code
- getCountry()
$country = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCountry(); - getCity()
$city = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCity(); - getCountryCode()
$country_code = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCountryCode(); - getRegion()
$region = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getRegion(); - getLatitude()
$lat = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getLatitude(); - getLongitude()
$long = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getLongitude(); - getPostal()
$postal = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getPostal(); - getTimezone()
$timezone = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getTimezone();
If you want to get all data together then just call
\Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail();
Ask your assistant about IP Address Lookup
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
More in the IP ecosystem
Most installed first
Activity
Releases
| Version | Type | Core | PHP | Release date | |
|---|---|---|---|---|---|
| 1.0.x-dev | Dev | 8–10 | Apr 24, 2023 |