Skip to content
Benjamin Pick edited this page Dec 30, 2019 · 41 revisions

Technically speaking, how could I verify if my visitor comes from Germany?

Put this code somewhere in your template files:

$userInfo = geoip_detect2_get_info_from_current_ip();
if ($userInfo->country->isoCode == 'de')
    echo 'Hallo! Schön dass Sie hier sind!';

To see which property names are supported, refer to the list of Record Properties or to the plugin's Lookup page.

How can I show text only if the visitor is coming from Germany?

There are no shortcodes for this. Instead, you should use CSS:

.geoip { display: none !important; }
.geoip-country-DE .geoip-show-DE { display: block !important; }
<div class="geoip geoip-show-DE">
Shipping to Germany is especially cheap!
</div>

You need to enable the option Add a country-specific CSS class to the <body>-Tag to make this work. See [API Usage Examples#css-use] for a more elaborate example.

How can I add the current country name as text in my page?

Add this plugin shortcode somewhere in the page or post content:

Wie ist das Wetter in [geoip_detect2 property="country.name" lang="de" default="ihrem Land"] ?

For more information, check the API Documentation and API Usage Examples.

Which data source should I choose?

Each source has its advantages and disadvantages:

Cost Precision Performance Registration
HostIP.info Free Low Low (Web-API) No
Maxmind GeoIP2 Lite City/Country database Free Medium High (File) Yes
Maxmind GeoIP2 City/Country database relatively high High High (File) Yes
Maxmind GeoIP2 Precision not so high (paid per lookup query, so good for low traffic/use) High Low (Web-API) Yes
ipstack free/not so high (paid per lookup query, so good for low traffic/use) High Low (Web-API) Yes
  • If you choose "automatic" and enter the account's api key, this plugin will install "Maxmind GeoIP2 Lite City" and update it monthly. This is the easiest option.
  • If you choose "manual", you can use any of the file-based Maxmind-Databases. It's recommended that you update the database regularly, for example by using the shell script provided by Maxmind.
  • If you choose "ipstack", note that the free plan does not allow HTTPS-Encryption of their lookup which is bad if you have to comply to GDPR.
  • Column Cost: Please refer to the vendor site to view current prices. The price depends on several factors: if you need city or country data, if pay per month, per year, or per query, etc.
  • Column Precision: To compare the commercial and the free data of Maxmind, see accuracy stats per country.
  • Column Performance: There are great differences how long a lookup can take. The Web-APIs take 0.5-1 second per Lookup (that's why they are cached for new each IP you request data from), the File-based APIs only about 0.01 second.

Can I change the time period how long the data is cached?

By default, lookups via Web-API are cached for 7 days. If you want to define a different time span, add this code somewhere in your theme or plugin:

if (!defined('GEOIP_DETECT_READER_CACHE_TIME'))
	define('GEOIP_DETECT_READER_CACHE_TIME', 14 * DAY_IN_SECONDS);

The Maxmind Lite databases are restricted by an EULA. Can I host a form where users can look-up the geographic information of an IP?

In general, no. Read the Site Licence Overview or the EULA for all details.

(This changed on Dec 30, 2019. Before, the databases were licenced "Creative Commons ShareAlike-Attribution" - this is not the case anymore.)

Does this plugin work in a WordPress MultiSite-Network environment?

There seem to be no issues with WordPress multisite, but it is not officially supported.

Is this plugin GDPR-compliant?

If your website is available in EU-countries, it must comply to GDPR-Regulations for privacy. Using this plugin is not GDPR-compliant per se, because it all depends on your use case and whether you explain it in your privacy policy.

  1. If you use a web-based source (hostip.info, Maxmind Precision, ipstack), the plugin stores all IPs that visited the site in a cache (by default for 7 days) for performance reasons. If you want to disable this behavior, add define('GEOIP_DETECT_READER_CACHE_TIME', 0); in your theme's function.php.

  2. If you use the source Ipstack.com, you must use encryption (thus you need to pay to ipstack.com because their free plans currently do not allow encryption).

  3. If you are using AJAX/JS mode, then the plugin is storing the geo-information of the user as a cookie. This should be mentioned in the privacy policy. You can disable the setting of the cookie by adding the following code in your theme's function.php - however, this will probably increase the server load (depending on your implementation).

add_filter('geoip_detect2_ajax_localize_script_data', function($options) {
    $options['cookie_name'] = '';
    return $options;
});
  1. Be especially careful when using geographic information in order to change the pricing amount or other selling options, as this might not be legal.

What do you mean by "This plugin is charity-ware"?

I have decided against trying to make this plugin profitable. Also, the work project I have been developing this for is long finished. If you want to encourage me to keep on maintaining this, and say "thank you for your work", please consider donating for this charity:

Youth With A Mission, Hainichen, Germany is a Christian non-profit organisation whose main aim is to strengthen the value of family in society.

Paypal Donate

Clone this wiki locally