Difference between revisions of "GeoIP2"

From TMM Wiki
Jump to navigationJump to search
Line 18: Line 18:
  
 
<pre>
 
<pre>
<?
+
<?php
echo 'According to geoip apache module, you are from '.apache_note("GEOIP_COUNTRY_NAME");
+
      include_once('../includes/procedures/GEOIP2/geoip2.phar');
echo '<br>According to geoip pecl php module, you are from '.geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
+
      $reader = new GeoIp2\Database\Reader('<PATH_TO_DB_FILE.mmdb>');
?>
+
      $record = $reader->country($_SERVER['REMOTE_ADDR']);
 +
      $country = $record->country->isoCode;
 +
      echo"$country is country\n";
 
</pre>
 
</pre>
 
'''Note: Please be sure to perform this test after you install or update Maxmind's GeoIP.
 
'''Note: Please be sure to perform this test after you install or update Maxmind's GeoIP.

Revision as of 19:42, 6 February 2019

NATS 4
Members Admin
The Members Admin
View Member Details
Add Member
MySQL Auth
Mod Authn DB
Multisite Access
Member Logging
Member Password Retrieval
OpenID Connect
Mod Auth OpenIDC
ID Numbers
NATS Configuration Admin
The Configuration Admin
Log Admin Activity
IP Address Filtering
MEMBER_EXPIRE_PAD
SKIP COUNTRIES
Fraud Configuration
Email Configuration
Affiliate Signup Email
Affiliate Postback
Affiliate Postback NEW
Affiliate Analytics
Throttling
NATS4 Terms of Service feature
GeoIP2

Download and install the GeoIP database from Maxmind.

There is a free one available here

You will need to download the 'Country' .mmdb file for both the paid and free one

This file needs to be on your NATS installation in a path that is accessible to NATS The path will need to be specified in config->surfer->tracking GEOIP2_PHP_DATABASE_LOCATION

You will then switch the IP_FILTER to GeoIP2_PHP and store your changes


Test Code

The following PHP code will help you test GeoIP. Put it in a file, put the file on your webserver, and load its URL. It should print your country's name.

<?php
       include_once('../includes/procedures/GEOIP2/geoip2.phar');
       $reader = new GeoIp2\Database\Reader('<PATH_TO_DB_FILE.mmdb>');
       $record = $reader->country($_SERVER['REMOTE_ADDR']);
       $country = $record->country->isoCode;
       echo"$country is country\n";

Note: Please be sure to perform this test after you install or update Maxmind's GeoIP.

See Also