Module

Developer
Supported

IP Geo Locator

ExpressionEngine 5

Back to this add-on's main page
View Other Add-ons From Climbing Turn

     

You must be logged in to post.

Add-on doesn’t work

Feature Request

WebAdmin
WebAdmin

Hi,

{exp:ip_geolocator:country_code} doesn’t work for me at all (I always get default value). Any ideas?

I use EE 5.2.6.

Thanks.

Anthony Mellor
# 1
Developer
Anthony Mellor

Hi,

It is possible that the Geo location service doesn’t recognise your IP address. To check this, try specifying an IP address like this:

{exp:ip_geolocator:country_code ip="216.58.213.100"

The above IP address is for www.google.com and should return a result. If it does then your IP address isn’t being recognised for some reason.

You can call the Geo Locator API directly by pasting http://www.geoplugin.net/json.gp?ip={YOUR IP ADDRESS} into your browser to check that it is working.

You can find more information on the Geo Locator API website: https://www.geoplugin.com/

I hope this helps.

Anthony

 

WebAdmin
# 2
WebAdmin

I did as you mentioned and I got: GB - so default value.

The thing is that my website uses load balancer so REMOTE_ADDR getting proxy server IP, not user IP.

I used the path to API you provided and my address has been recognized properly. An address of load balancer created “null” responses so that’s the problem I think.

Won’t be better to use HTTP_X_FORWARDED_FOR instead of REMOTE_ADDR?

Anthony Mellor
# 3
Developer
Anthony Mellor

Hi,

Thanks for your feedback - it is very useful. As a result we will add a switch to the add-on to enable it to use HTTP_X_FORWARDED_FOR. Hopefully we’ll get this into the next release in a couple of weeks.

For now you can replace REMOTE_ADDR with HTTP_X_FORWARDED_FOR in the add-on in the code - see line 399 in mod.ip_geolocator.php.

The add-on was just for simple IP lookups and wasn’t designed to be used behind a proxy but we will improve on this.

Kind regards

Anthony

 

WebAdmin
# 4
WebAdmin

Yep, I changed that and Geolocator started working but.. not as expected.

API works well - I should get Denmark country code and I got it here: http://www.geoplugin.net/json.gp?ip=185.134.30.248. Unfortunately at the same time Geolocator shows: US.

HTTP_X_FORWARDED_FOR creates the list of IP’s so before we will assign it to $ip we should change it to an array and then grab the first item from an array.

I replaced this line:

$ip $_SERVER['REMOTE_ADDR']

by this one:

$ip_forwarded $_SERVER['HTTP_X_FORWARDED_FOR'];
$ip_array explode(', '$ip_forwarded2);
$ip $ip_array[0]

and IP Geolocator started working properly.

 

Anthony Mellor
# 5
Developer
Anthony Mellor

Thanks for the feedback - we will update the add-on.