How to detect location IP and not Smart IP

Created on 4 July 2018, over 6 years ago
Updated 28 November 2024, 24 days ago

Hi I am not sure how to detect my ip. I have used all the methods suggested like:
$myIp = \Drupal::request()->getClientIp();
$userip = $_SERVER['REMOTE_ADDR'];
$location = \Drupal::service('smart_ip.smart_ip_location');
$event = \Drupal::service('smart_ip.get_location_event');
$locations = $event->getLocation();
$ipAddress = $locations->get('ipAddress');
$test = \Drupal::request()->getClientIp();

All of these only return my local ip: 192.168.25.8

Am I doing something wrong? Is there a function to return my actual location IP.

Till now I was using a different service to get the ip address:
$ip = file_get_contents('https://api.ipify.org'); <- EXTERNAL SERVICE
$location = SmartIp::query($ip);
// $ip = \Drupal::request()->getClientIp();
if (!empty($location['country'])) {
$detected_location = $location['country'];
}
elseif ($location['originalData']['registered_country']) {
$detected_location = $location['originalData']['registered_country']['names']['en'];
}

But now there has been a requirement to remove all external services to get user IP. So I haven't figured out a way to get it using SMART:IP.
Please let me know of a solution.

💬 Support request
Status

Postponed: needs info

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • heddn Nicaragua

    Drupal 8 & 9 are no longer supported. This version of the module this was opened against only supports these earlier versions of Drupal. If this is still something you want addressed in the current 5.x version of the module, please update and provide some next steps.

Production build 0.71.5 2024