Home > General > Affiliate Marketing Forum

Simple GEO redirect based on city? (6)


10-24-2011 07:09 AM #1 profitable ()
Simple GEO redirect based on city?

Does anyone know of a simple geo redirect script that will redirect users based on their city? I'm not sure i can handle Maxmind installation so was curious if there was a simple way to do it.

I did find the Country redirect script on the StackThatMoney site:
[PHP]<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>


<script language="JavaScript">

var country= geoip_country_code();

if(country == "US")
{
<!--
window.location = "YOUR US OFFER"
//-->
}

else
{
<!--
window.location = "OTHER OFFER URL"
//-->
}

</script>[/PHP]

I'm curious if there is a script like this for city/state?


10-24-2011 08:00 AM #2 zeno (Administrator)

There may be some free ones out there but you will probably have to deal with 1) a lack of accuracy and 2) page loads waiting on contacting their server + if their server goes down you lose it all. I lost georedirection completely when I was using a third party script and I was super lucky to realise 5 minutes after it went down.

In the long run you will be better off using your own server to handle it. If you have good hosting you should be able to get them to install the GeoLite City database and php/apache extensions for you, and once you learn how to control the redirects yourself you will have saved yourself future issues. Think of how much money you could blow if you were pushing $1000 a day worth of traffic and your redirects blackholed your clicks for half the day.


10-24-2011 03:32 PM #3 matter3 (Member)

I believe you can get the state and city using the JS you've shown. I'll have to dig it up in a second here from one of my LPs.

Edit:

[PHP]
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript">

var city = geoip_city();
var state = geoip_region();

if (...){
do this;
}
else{
do this;
}

</script>
</span>
[/PHP]
If you play around with that you should be able to get what you want to do. I edited it a bit again, not sure if that's exactly what you need but hope it gets you somewhere.


10-24-2011 04:03 PM #4 profitable ()

Looks close, i'll give it a shot. Can this script handle PPV? medium volume? 100k-200k pops/day?

Quote Originally Posted by matter3 View Post
[PHP]
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript">

var city = geoip_city();
var state = geoip_region();

if (...){
do this;
}
else{
do this;
}

</script>
</span>
[/PHP]


10-24-2011 04:11 PM #5 matter3 (Member)

Never tested it with PPV so you'll have to see for yourself. I'd recommend putting the actual JS file on your server though so you don't have to rely on maxmind's, should help with speed too.


10-24-2011 06:59 PM #6 tijn (Moderator)

rather then using the JS version of the maxmind geoip database, just ask your hosting company to make sure the following extension is enabled:

http://www.php.net/manual/en/intro.geoip.php

then use something like this (did this from the top of my head and didnt debug it so you might need to tweak it here or there)

Code:
$geodata = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
$city = $geodata['city'];
switch ( $city ) {
case 'city1string':
    $url = 'http://domain1.com';
    break;
case 'city2string':
    $url = 'http://domain2.com';
    break;
default:
    $url = 'http://domain3.com';
}


Home > General > Affiliate Marketing Forum