viagra online without prescription vicodin online buy percocet buy adderall
New Webmasters > Featured > Make Money All Over The World With Geographic Targeting

Make Money All Over The World With Geographic Targeting

Many websites that feature product reviews or recommended reading lists like to link people to Amazon so they can look at the product and buy it for themselves. The authors of these websites like to put their Amazon affiliate tag into the link so they can earn a small comission from the sales.

The problem that I, and a lot of people have, is that Amazon has many different sites and you need to sign up to the affiliate program for each site separately.

For example, if you are registered with the affiliate program, you cannot use that affiliate tag on a link to

Make money all over the world

Make money all over the world

Perhaps you think “why not just sign up to each affiliate program separately? This is not a problem. The problem comes with making sure your website visitors see a link to the correct Amazon store for them.

For example, visitors from the US should see a link to, with your affiliate tag. Visitors from France should see a link to with your affiliate tag.

Identifiying The User’s Country With Maxmind

Maxmind is a service that takes any IP address supplied by you and tells you the country, state (or region), city and latitude and longitude. The service is not free, but the prices are very reasonable. You can get 200,000 IP address lookups for just $20. There is nothing to download as you simply make your lookup request to the Maxmind servers. Also, the credits never expire so you don’t have to use them up within a certain time limit.

You have to supply the service with the IP address to look up first. There are many ways to detect a user’s IP address in PHP, but this is how I go about doing it:

function getRealIpAddr()
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    return $ip;

Once you have detected the user’s IP address you need to access the Maxmind web service. There is some sample code on the Maxmind website, but I will guide you through it now using PHP.

Maxmind offer two services, one that returns the location and the other which returns the location and ISP details. We will just use the location one as all we are looking for is the country.

The service is accessed with the following URL:

It takes 2 parameters:

  • i (lowercase I) – which is the IP address you are checking
  • l (lowercase L) – your own licence key

Here is an example with a dummy IP address and licence key

This is the PHP code that we are going to use to return our information:

$query = "" . $license_key . "&i=" . $ipaddress;
$url = parse_url($query);
$host = $url["host"];
$path = $url["path"] . "?" . $url["query"];
$timeout = 1;
$fp = fsockopen ($host, 80, $errno, $errstr, $timeout)
	or die('Can not open connection to server.');
if ($fp) {
  fputs ($fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n");
  while (!feof($fp)) {
    $buf .= fgets($fp, 128);
  $lines = split("\n", $buf);
  $data = $lines[count($lines)-1];
} else {
  # enter error handing code here
echo $data;
$geo = explode(",",$data);
$country = $geo[0];
$state = $geo[1];
$city = $geo[2];
$lat = $geo[3];
$lon = $geo[4];

After all this effort we get what we were trying to find.

Contained inside the variable $country is a two letter country code that indicates the visitor’s location.

Those that are relevant to us are:

  • US – USA
  • GB – Great Britain (UK)
  • CA – Canada
  • FR – France
  • DE – Germany
  • JP – Japan
  • CN – China

These are all the countries that Amazon operates websites in. The ones that you choose to use depends on the target audience of your website. Most English langage sites will just focus on the US, UK and Canadian markets.

How to Display The Correct Product Links

Now we finally get to the meat of the article. We have joined our appropriate affiliate programs, detected where our visitor is, so now we need to display the correct code.

if($country == "UK")
     // Display our UK affiliate code here
elseif($country == "CA")
     // Display our Canadian affiliate code here
     // Display our US affiliate code here

What this code does is displays the Canadian or UK affiliate code if the user is in either one of those countries. If not, then display the US code. The US code will be displayed as a fall back if the script cannot detect the location, or the visitor is in one of those countries we are not catering for.

Geographic targetting is not 100% reliable and you should always have a fallback incase the scripts encounter any problems (like displaying affiliate code for the US site if the script is not sure where the visitor is from).

I hope this code helps you to make a lot more money from Amazon. Feel free to post any comments or questions below.

Be Sociable, Share!


3 comments for “Make Money All Over The World With Geographic Targeting”

  1. geo targeting has changed online marketing alot – epecially useful for advertisers as they can now narrow down and target a specific location and FORCE publishers to adhere to it. Few years back this was not possible.

    What do u thing is next with online marketing?

    Posted by geoip | June 25, 2010, 2:33 am
  2. So, if I get all this code right it will automagically change my links to the proper version of Amazon?

    Could I not just use the Amazon affiliate link localizer plugin to accomplish this, or am I missing something?

    Posted by Deodorant James | August 3, 2010, 3:41 am
  3. Hi, I made a WordPress plugin that does all this for you, so you don’t have to worry about any of the above:

    Posted by Pete Williams | June 26, 2011, 8:21 am

Post a comment

viagra online without prescription vicodin online buy percocet buy adderall