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

[Request] PHP Geo Redirect

Discussion in 'Black Hat SEO' started by MandatoryMagic, Jul 27, 2009.

  1. MandatoryMagic

    MandatoryMagic Registered Member

    Joined:
    Jul 10, 2009
    Messages:
    91
    Likes Received:
    39
    Occupation:
    YouTube Master/Conversion Wizard
    Location:
    YouTube Master/Conversion Wizard
    Something similar to the second one in this thread http://www.blackhatworld.com/blackhat-seo/making-money/92299-simplest-geo-redirect-code.html

    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>
    BUT in PHP. I'm only requesting this because many people disable javascript.

    So if someone can code this up real quick or can point me in the direction of a PHP Geo Redirect that would be lovely.
     
    • Thanks Thanks x 1
  2. zackster

    zackster Registered Member

    Joined:
    Jan 9, 2009
    Messages:
    66
    Likes Received:
    33
    GodCPA uses geo targeting that is actually quite simple. Or just google geo targeting
    Posted via Mobile Device
     
  3. MandatoryMagic

    MandatoryMagic Registered Member

    Joined:
    Jul 10, 2009
    Messages:
    91
    Likes Received:
    39
    Occupation:
    YouTube Master/Conversion Wizard
    Location:
    YouTube Master/Conversion Wizard
    I notice though that it is used in an iframe. Is it possible to locate the code just for Geo Redirecting *without* the iframe.
     
  4. w84it

    w84it Regular Member

    Joined:
    Jun 18, 2009
    Messages:
    442
    Likes Received:
    752
    hey, checkout www.geoio.com

    Its as simple as calling :
    Code:
    [URL="http://api.geoio.com/q.php?key=5NPWwjiBd6J6LpKd&qt=geoip&d=pipe&q=VisitorIP"]http://api.geoio.com/q.php?key=secretkeyyougetfromsite&qt=geoip&d=pipe&q=VisitorIP[/URL]
    So if I call
    Code:
    [URL="http://api.geoio.com/q.php?key=5NPWwjiBd6J6LpKd&qt=geoip&d=pipe&q=68.151.233.111"]http://api.geoio.com/q.php?key=secretkeyyougetfromsite&qt=geoip&d=pipe&q=68.151.233.111[/URL]
    it returns
    Code:
    Lloydminster|Alberta|Canada|Shaw Communications Inc|53.28|-110
    Now with php just do an explode() with that string and | as the seperator and you will end up with an array where array(2) would = Canada

    From there on you can just do the redirect which is easy.
     
  5. MandatoryMagic

    MandatoryMagic Registered Member

    Joined:
    Jul 10, 2009
    Messages:
    91
    Likes Received:
    39
    Occupation:
    YouTube Master/Conversion Wizard
    Location:
    YouTube Master/Conversion Wizard
    If it's easy could you please post the code here. Sorry man but I just suck at PHP. Please, it would be a huge help to me!
     
  6. skweekykleen

    skweekykleen Newbie

    Joined:
    Jul 8, 2008
    Messages:
    45
    Likes Received:
    68
    Here's the basic code you need to do this with PHP using the GeoIO API...

    First, setup an account with GeoIO, then log in, click API, and create a new API call by choosing:

    Query Type: IP Address to Geographical Location
    Delimiter: Pipe (|)

    Then copy and paste the whole URL from the text box...it should look something like this:

    PHP:
    http://api.geoio.com/q.php?key=XXXXXXXXXXX&qt=geoip&d=pipe&q=YOUR QUERY HERE
    That line is what you will paste into the code for "api_url" -- Here is the code, hope it helps:

    PHP:
    <?php

    //    adjust the following lines as needed...
    $us_offer_url    "http://URL_TO_USA_LANDING_PAGE.com";
    $uk_offer_url    "http://URL_TO_UK_LANDING_PAGE.com";
    $intl_offer_url    "http://URL_TO_INTERNATIONAL_LANDING_PAGE.com";

    //    paste the URL from the geoio backend...
    $api_url "http://api.geoio.com/q.php?key=XXXXXXXXXXXX&qt=geoip&d=pipe&q=";

    //    DONT EDIT BELOW HERE UNLESS YOU KNOW PHP...
    $api_url .= $_SERVER['REMOTE_ADDR'];
    $f explode("|"file_get_contents($api_url));

    if(
    trim($f[2]) == "United States") {
        
    header("Location: $us_offer_url");
    } elseif(
    trim($f[2]) == "United Kingdom") {
        
    header("Location: $uk_offer_url");
    } else {
        
    header("Location: $intl_offer_url");
    }

    exit();

    ?>
     
    • Thanks Thanks x 5
    Last edited: Jul 28, 2009
  7. MandatoryMagic

    MandatoryMagic Registered Member

    Joined:
    Jul 10, 2009
    Messages:
    91
    Likes Received:
    39
    Occupation:
    YouTube Master/Conversion Wizard
    Location:
    YouTube Master/Conversion Wizard
    That's awesome skweekykleen! Just one question... How would you add more countries? I assume you do another else if and then add the url at the top but then the whole "trim" thing confused me. Could you please put an example with 2 more countries, for instance GB and CA?
     
  8. MandatoryMagic

    MandatoryMagic Registered Member

    Joined:
    Jul 10, 2009
    Messages:
    91
    Likes Received:
    39
    Occupation:
    YouTube Master/Conversion Wizard
    Location:
    YouTube Master/Conversion Wizard
    Oh snap I think I got it. Tell me if this is write if you want to add GB and CA for instance. *I know GB is UK it's just an example for adding more countries...*

    Also why do you put in titles like writing out "United States"?

    PHP:
    <?php

    //    adjust the following lines as needed...
    $us_offer_url    "http://URL_TO_USA_LANDING_PAGE.com";
    $uk_offer_url    "http://URL_TO_UK_LANDING_PAGE.com";
    $gb_offer_url    "http://URL_TO_GB_LANDING_PAGE.com";
    $ca_offer_url    "http://URL_TO_CA_LANDING_PAGE.com";
    $intl_offer_url    "http://URL_TO_INTERNATIONAL_LANDING_PAGE.com";

    //    paste the URL from the geoio backend...
    $api_url "http://api.geoio.com/q.php?key=XXXXXXXXXXXX&qt=geoip&d=pipe&q=";

    //    DONT EDIT BELOW HERE UNLESS YOU KNOW PHP...
    $api_url .= $_SERVER['REMOTE_ADDR'];
    $f explode("|"file_get_contents($api_url));

    if(
    trim($f[2]) == "United States") {
        
    header("Location: $us_offer_url");
    } elseif(
    trim($f[2]) == "United Kingdom") {
        
    header("Location: $uk_offer_url");
    } elseif(
    trim($f[2]) == "GB") {
        
    header("Location: $gb_offer_url");
    } elseif(
    trim($f[2]) == "Canada") {
        
    header("Location: $ca_offer_url");

    } else {
        
    header("Location: $intl_offer_url");
    }

    exit();
     
  9. designsonline

    designsonline Power Member

    Joined:
    Jan 22, 2009
    Messages:
    651
    Likes Received:
    145
    Location:
    UK
    www.geoio.com seems pretty inaccurate for the UK, (It got my location and provider completely wrong...)

    Does anyone know of a free alternative that is good for the UK?
    Cheers
     
  10. stryker336

    stryker336 Newbie

    Joined:
    Dec 28, 2008
    Messages:
    48
    Likes Received:
    5
    Occupation:
    Student/Internet Marketer
    Location:
    Philadelphia
    Home Page:
    This is awesome got it working without a problem. However, they do charge for anything over 1000 hits a day. Is there any other site which is free or can we run a script on our server that does something similar?
     
  11. xhpdx

    xhpdx Regular Member

    Joined:
    Sep 21, 2008
    Messages:
    331
    Likes Received:
    2,160
    Occupation:
    Coder
    Location:
    EU
  12. xhpdx

    xhpdx Regular Member

    Joined:
    Sep 21, 2008
    Messages:
    331
    Likes Received:
    2,160
    Occupation:
    Coder
    Location:
    EU
    you can try this code with the geolite from maxmind
    PHP:
    require ('geoip.inc');
    $gi geoip_open('GeoIP.dat',GEOIP_STANDARD);
    $country_code geoip_country_code_by_addr($gi$_SERVER['REMOTE_ADDR']);

    if 
    $country_code="US"
    header("Location: http://your_us_offer");

    elseif 
    $country_code="UK"
    header("Location: http:/your_uk_offer");

    # if user is not from us or uk, send him international offer
    else header("Location: http://your_international_offer");
     
    • Thanks Thanks x 2
  13. invest207

    invest207 Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 20, 2008
    Messages:
    542
    Likes Received:
    70
    Location:
    Mars
    Your code woks. But how do I modify so it redirects only US visitors and keeps all others on page where code is inserted (I dont want to redirect the others in any way)

    Help would be appreciated.