Need A Geolocation Script To Redirect Users Based On Their Location? Here’s One!
One of the most common things that you’ll do in affiliate marketing is redirect people based on their country. Whether you’re making use of a traffic source where visitors come from every which where, or whether you’re making sure Facebook ad approvers don’t freak out, you’ll use this code over and over again.
So, here’s a quick plug-and-play script to get everything working straight away.
NOTE – if you’re using the Stack That Money mobile tracker (which works for Web too), you don’t need to do this – redirection is built in.
Setup
First of all, you’ll need to follow these instructions to install the new Maxmind GeoIP database. That means that your IP-based location detection will be as accurate as possible.
Creating The Script
Next, create a new PHP file on the server you’ve installed the GeoIP database on – call it whatever you like.
Copy and paste this code into it:
<?PHP
require $_SERVER.'/vendor/autoload.php';
$ipaddress = $_SERVER;
use GeoIp2DatabaseReader;
$reader = new Reader('$_SERVER./geolocation/GeoLite2-City.mmdb');
$record = $reader->omni($ipaddress);
$subid = $_GET;
switch($record->country->isoCode) {
Settin ...