Simplest Geo-Redirect Code

avi_31337

Regular Member
Joined
Jan 9, 2008
Messages
268
Reaction score
151
Here is my simple geo redirect page that I have coded myself using the free Maxmind API. Write this as an html file in the landing page, so that all the USA traffic get redirected to your destination address. This is my first share and encourage me if u love em.


Code:
<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>

Save this simple code as an HTML file and maintail that as your landing page. The Country specific traffic will be automatically transfered to the destination.
 
Im looking for a more specific script that will detect the an ip is visiting the website from say Basildon!

Anyone know where there is a download for this?
 
Sorry my JS isnt up to scratch, but cant you do it as a Case Select rather than a nested IF statement?

i.e. If its either US, UK, other, go here, here and here respectively.
Instead of: If its US go here, else if UK go here, else if other go here... ?
 
Something like this:

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

var country = geoip_country_code();

switch (country)
{
case (country = "US"):
  window.location = "YOUR US OFFER";
break;
case (country = "UK"):
  window.location = "YOUR UK OFFER";
break;
default:
  window.location = "YOUR INTERNATIONAL OFFER";
break;
}
</script>

????

Obviously you need to know if UK is "UK", "EN", "England", etc

P.S I haven't tested it...
 
I think you can also use google api for this.
 
How was it much better? How do they differ?

I've tested myself and I see that Maxmind is returning much appropriate locations than the google API...

I've tested in concern with the city name, lat & lon, postal code etc....

In regardance with country all API will be almost the same, difference arises when comes to city names and other in depth details.....
 
Here is my simple geo redirect page that I have coded myself using the free Maxmind API. Write this as an html file in the landing page, so that all the USA traffic get redirected to your destination address. This is my first share and encourage me if u love em.


Code:
<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>

Save this simple code as an HTML file and maintail that as your landing page. The Country specific traffic will be automatically transfered to the destination.


Code is working. But I need a small modification. I need to redirect only the US visitors to another page. I dont want to redirect all the others.

Please help me with this.
 
INVEST!! haha are you kidding me. alright obviously... You put your url you want to redirect people to for us only in the if country us one. THEN FOR ELSE, duhh... You put the current url the people are on. Or even better. under the else statement just laeve it blank.
 
How can I get it to the state and city level?
Let say the user will only see the offer if he live in New york city for example.


thanks
 
Great the code is working perfectely for me.

I was however wondering how i can add more than one contry to be redirected
For instances, instead of the below which would be US countries only, can i add more countries, like in the second code window
Code:
if(country  == "US")

Code:
if(country  == "US,UK,ZA")
 
Nybody have any idea on the above, and if using multi countries like that will work
 
I think you can try:

Code:
if(($country == "US") || ($country == "UK") || ($country == "ZA"))
 
Last edited:
I think you can try:

Code:
if(($country == "US") || ($country == "UK") || ($country == "ZA"))

I have tried like you suggested but it does not seem to work. It is just loading a blank page when i use it like you suggest.

I was wondering if it will work if i just add the if's below each other like the following
Code:
if(country  == "US")
if(country  == "GB")
if(country  == "SG")

I am just guessing and hope maybe one of you clever scrioipt or code dude can help me out here
 
Just to summarise again, i want to redirect multiple countriesd so wondering if this will work
Code:
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>


<script language="JavaScript">

var country= geoip_country_code();
  
[B]if(country  == "US")
if(country  == "GB")
if(country  == "SG")   [/B] 
{
<!--
window.location = "YOUR US OFFER"
//-->
}

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

</script>
 
i guess switch methode is better than if then else as if then is making a loop in the scripts.
just my 0 cents.
 
i guess switch methode is better than if then else as if then is making a loop in the scripts.
just my 0 cents.


I always use the case switch in my PHP scripts - it is a lot easier to read than the if/else never ending nested loop hell :D
 
I tested this script with a Brazilian proxy and I was still taken to the US offer... any idea if this script is now out of date or?

I know this is an old thread but I am actually testing this script and its not working... I'm not keyboard jockeying.

Perhaps my brazilian proxy isn't working, even though whatismyipaddress dot com shows it as being brazil....
 
Last edited:
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features and essential functions on BlackHatWorld and other forums. These functions are unrelated to ads, such as internal links and images. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock