1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simplest Geo-Redirect Code

Discussion in 'Making Money' started by avi_31337, Jun 20, 2009.

  1. avi_31337

    avi_31337 Regular Member

    Joined:
    Jan 9, 2008
    Messages:
    266
    Likes Received:
    145
    Location:
    Planet Earth
    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.
     
    • Thanks Thanks x 30
  2. designsonline

    designsonline Power Member

    Joined:
    Jan 22, 2009
    Messages:
    651
    Likes Received:
    145
    Location:
    UK
    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?
     
  3. Wikolia

    Wikolia Junior Member

    Joined:
    Sep 26, 2008
    Messages:
    130
    Likes Received:
    38
    Location:
    Dark side of the moon
    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... ?
     
  4. Wikolia

    Wikolia Junior Member

    Joined:
    Sep 26, 2008
    Messages:
    130
    Likes Received:
    38
    Location:
    Dark side of the moon
    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...
     
  5. avi_31337

    avi_31337 Regular Member

    Joined:
    Jan 9, 2008
    Messages:
    266
    Likes Received:
    145
    Location:
    Planet Earth
    • Thanks Thanks x 1
  6. arthro

    arthro Regular Member

    Joined:
    Aug 18, 2008
    Messages:
    258
    Likes Received:
    13
    I think you can also use google api for this.
     
  7. avi_31337

    avi_31337 Regular Member

    Joined:
    Jan 9, 2008
    Messages:
    266
    Likes Received:
    145
    Location:
    Planet Earth
    As far as I know, we can make use of the google maps API to do so.....

    But Maxmind API is what I use and much better....
     
    • Thanks Thanks x 1
  8. arthro

    arthro Regular Member

    Joined:
    Aug 18, 2008
    Messages:
    258
    Likes Received:
    13
    How was it much better? How do they differ?
     
  9. avi_31337

    avi_31337 Regular Member

    Joined:
    Jan 9, 2008
    Messages:
    266
    Likes Received:
    145
    Location:
    Planet Earth
    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.....
     
  10. invest207

    invest207 Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 20, 2008
    Messages:
    542
    Likes Received:
    70
    Location:
    Mars

    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.
     
  11. MandatoryMagic

    MandatoryMagic Registered Member

    Joined:
    Jul 10, 2009
    Messages:
    91
    Likes Received:
    39
    Occupation:
    YouTube Master/Conversion Wizard
    Location:
    YouTube Master/Conversion Wizard
    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.
     
  12. dexterfly

    dexterfly Regular Member

    Joined:
    Dec 14, 2008
    Messages:
    256
    Likes Received:
    82
    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
     
  13. royalmice

    royalmice BANNED BANNED

    Joined:
    Aug 23, 2007
    Messages:
    1,186
    Likes Received:
    982
    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") 
     
  14. royalmice

    royalmice BANNED BANNED

    Joined:
    Aug 23, 2007
    Messages:
    1,186
    Likes Received:
    982
    Nybody have any idea on the above, and if using multi countries like that will work
     
  15. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    I think you can try:

    Code:
    if(($country == "US") || ($country == "UK") || ($country == "ZA"))
    
     
    Last edited: Oct 2, 2009
  16. royalmice

    royalmice BANNED BANNED

    Joined:
    Aug 23, 2007
    Messages:
    1,186
    Likes Received:
    982
    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
     
  17. royalmice

    royalmice BANNED BANNED

    Joined:
    Aug 23, 2007
    Messages:
    1,186
    Likes Received:
    982
    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>
     
  18. plut0

    plut0 Regular Member

    Joined:
    Aug 2, 2008
    Messages:
    255
    Likes Received:
    59
    i guess switch methode is better than if then else as if then is making a loop in the scripts.
    just my 0 cents.
     
  19. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home

    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
     
    • Thanks Thanks x 2
  20. chocolatemonkey

    chocolatemonkey Junior Member

    Joined:
    Dec 20, 2009
    Messages:
    197
    Likes Received:
    29
    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: Feb 4, 2011