meta data for this page
  •  
Translations of this page:

Using GeoIP to auto-fill the Country dropdown in the phpList subscribe page

If you have configured an attribute called “country”, which is a “select” type attribute, you can use GeoIP to automatically set the selected value to the country that the subscriber is located in.

Currently, this only works with an attribute that is called “Country” in English, other languages won't work.

GeoIP is a system provided by MaxMind, which maps IP addresses to geographical locations on the planet. There is a free version available, or you can pay for a more advanced set of data.

Configure Apache

The example is for Debian/Ubuntu based systems, but it will be similar on other Linux distributions. Also, these instructions are for the Apache webserver, and other servers like Nginx will be different.

Install the Apache module

sudo apt install libapache2-mod-geoip

Configure the module

edit /etc/apache2/mods-available/geoip.conf

<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
</IfModule>

If your webserver is behind a proxy, you need to add this line

GeoIPScanProxyHeaders On

Now, when someone visits your subscribe page the “country dropdown” will automatically be set to the country they are visiting from. This is only when the value is not already set. The subscriber will then be able to change it, in case they are travelling.