Maxmind geolitecity wordpress hosting

I am trying to add Geo IP to a site im working on; i have used Context geo IP and Geo IP modules and am able to create a context based on a country. However i need to display content based on region/city.

Im using MaxMinds' GeoIP.dat file (which i can get to work) but when i try to use GeoLiteCity.dat file i get no region/city options - i cannot figure out how to use it.

Has any one used this before and can perhaps point me in the right direction, e.g. tutorials, videos etc. Perhaps someone has used an alternative module that works 'out of the box'?

Maxmind geolitecity wordpress hosting context module

Any advice would be greatly appreciated.

JamesOakley commented 14 May 2013 at 17:40

I don't know about those two modules, but I've found I have most success putting the Apache module from MaxMind and/or the PHP Extension onto the server, then just using the server variables / PHP function library.

What hosting are you on - do you have any control over such things? I could point you in the right direction for setting that up - if you have root access.

JamesOakley commented 15 May 2013 at 09:49

Hi I've done a bit more digging

First, I've found that installing GeoIP on a server (as PECL extension or Apache module), I need to rename GeoLiteCity.dat to GeoIPCity.dat for the relevant code to pick it up. It may be that you need to do this if you are using the City data file with the GeoIP API module.

However: Second, I've looked at the code of the GeoIP context module, and it only uses the country level data. See drupalcode.org/project/context_geoip.git/blob/refs/heads/7.x-1.x. .

So if you wanted to persevere with these two modules, I'd try two things (corresponding to those two observations above):

First, make sure that other PHP code is reading the City data. Try enabling (temporarily) the PHP input filter module (in core), and creating a node that prints out the city of your current IP address. Does it work? Try renaming the City data file as above. Does it work? Until you can get that code to work, the context module won't pick the city-level data up either.

Second, you could modify the GeoIP context module so that it can read that city function instead or as well. Or you could open an issue in the issue queue asking for this as a feature request.

Anonymous (not verified) commented 15 May 2013 at 11:32

Thanks for that, i shall give this a go now to see if i can get something working.

ill post my findings.

Anonymous (not verified) commented 15 May 2013 at 11:09

thanks for getting back to me. I am ideally looking for a way to serve content to each country in the UK; the context geo ip module only gives United Kingdom as an option. I should be fine for getting mod_geoip2 Apache module installed.

Maxmind geolitecity wordpress hosting have used

I would however be interested in knowing how i could serve/display content. Having looked at "dev.maxmind.com/geoip/legacy/mod_geoip2#Output_Variables-7 " for a list of variables available, i would imagine id use a simple if - else statement using 'GEOIP_COUNTRY_NAME', inside a template, e.g. node--basic-page:

The example is rather contrived, but is something i can get a 'handle' on. Do you have any examples/point me to existing articles of using the API? That would be really useful!

JamesOakley commented 15 May 2013 at 11:34

I'm having a look to see what output I get

In PHP, to get access to those Apache variables, you need to use
$_SERVER['GEOIP_COUNTRY_NAME']

So, yes, in theory you could then do
if ($_SERVER['GEOIP_COUNTRY_NAME'] == 'England')

except that, when I look at all the data I get from using the city database with PECL, I get the following for my own IP:

Array ( [continent_code] => EU [country_code] => GB [country_code3] => GBR [country_name] => United Kingdom [region] => J9 [city] => London [postal_code] => [latitude] => 53 [longitude] => -1 [dma_code] => 0 [area_code] => 0 )

Nowhere there does it say "England". You can have GB, GBR or United Kingdom. Then next level of detail in is City. Mine isn't actually "London" - it's a lot more specific than that, so there's no way you could have a list of all Welsh cities. ("Swansea", "Cardiff" wouldn't do it - you'd get "Mumbles", "Gower", "LlanfairPG", and loads more coming through). The best you could do would be to approximate through latitude and longitude - but that would be pretty inaccurate.

Anonymous (not verified) commented 15 May 2013 at 16:12

Cheers for the advice James, thats been really helpful thanks. Im on hold for the moment, im currently talks with my web host - im on shared hosting so they wont allow custom apache modules unless i upgrade to dedicated or VPS.

If this is a no go, do you know of any other geo ip solutions? Iv just taken a look at the JS alternative (dev.maxmind.com/geoip/geoip2/javascript ) - ever tinkered with that?

Related articles

Blog hosting script wordpress themesJavaScript will work within WordPress. If used within the template files. most JavaScript will work fine. Here are a few tips to make your JavaScript work in WordPress. JavaScript in Template...
Magic quotes gpc off wordpress hostingAsked: 2013-05-04 11:24 am EST Hello, I started using Joomla 3 and now have problems and was told magic quotes need to be off for it to function correctly. Using live chat they said I could...
Blog hosting script wordpress widgetsJavaScript will work within WordPress. If used within the template files. most JavaScript will work fine. Here are a few tips to make your JavaScript work in WordPress. JavaScript in Template...
Phpsessid cookie wordpress hostingSessions, Cookies and You. Getting the most cache for your buck. This post is going to walk you through what a session and cookie is, how it works, and how they effect the speed of your...
Embed wordpress blog into website hostingA lot of conversation is shifting away from traditional websites and blog comments to social media. Often while writing an article, I like to refer to a discussion happening on Facebook,...