I was looking for a plugin / extra which would work with MaxMind GeoIP2 or GeoLite2 to return a value on user’s supposed country of origin in order to direct to appropriate language content. I couldn’t find anything, nor much discussion - strange, seeing as how common this is over in WordPress land.
Does anyone have any experience or a successful Modx snippet example of using Geo IP database for querying user geo location?
I think, thats because you don’t need much of an Extra and I think, you can just create a snippet, following the examples
maxmind/GeoIP2-php: PHP API for GeoIP2 webservice client and database reader (github.com)
after you have downloaded and installed the php api
Cheers, Bruno, we’ll take a look. JS may be the easier
Had a similar challenge. Easy to do with a snippet. This will show the city based on IP.
$ip = $_SERVER['REMOTE_ADDR'];
$location = 'unknown';
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
if( isset($details->city) ){
$location = $details->city;
}
2 Likes
You can also check out geocoder, which lets you use different functions from a provider of choice.