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

[REQ] Geo Targeting Script

Discussion in 'Black Hat SEO Tools' started by blade, Nov 5, 2008.

  1. blade

    blade Regular Member

    Joined:
    Jul 29, 2008
    Messages:
    330
    Likes Received:
    114
    Hi,

    I need a script for geo targeting. Need to direct traffic to different landing pages according to the surfer's IP.

    I looked and didn't find such a script on BHW which is a bit strange since its kind of a basic marketing tool...

    To clarify: If the surfer is from the U.S. I need him to get to landing page #1, If he is from Spain to landing page #2, if he is from France to landing page #3 and if he is from any other country to landing page #4.

    Appreciate your help,
    Blade.
     
  2. blade

    blade Regular Member

    Joined:
    Jul 29, 2008
    Messages:
    330
    Likes Received:
    114
    I'm willing to pay for such a script. Please help with this matter...
     
  3. apekillape

    apekillape Senior Member Premium Member

    Joined:
    Dec 13, 2007
    Messages:
    1,077
    Likes Received:
    1,441
    Occupation:
    Basically, I just walk the Earth.
    Location:
    The Layer Cake
  4. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    What language do you want this in, PHP?
    I have done this before in PHP and Perl so can give you a hand.

    PM if you are interested.
     
  5. cyklotrial

    cyklotrial Regular Member

    Joined:
    Oct 13, 2008
    Messages:
    248
    Likes Received:
    82
    Location:
    Wonderland
    PHP:
    <?php 
    // Get country code corresponding to an IP address 

    function get_country_code ($ip) {
    $c curl_init();
    curl_setopt($cCURLOPT_URL"http://www.topwebhosts.org/whois/index.php?query=$ip");//otwieramy Å‚acze ze strona
    curl_setopt($cCURLOPT_HEADER1);
    curl_setopt($cCURLOPT_VERBOSE1);
    curl_setopt($cCURLOPT_RETURNTRANSFER,1);
    curl_setopt($cCURLOPT_USERAGENT'Mozilla/5.0 (X11; U; Linux i686;pl; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3');
    curl_setopt($cCURLOPT_ENCODING'gzip');
    curl_setopt($cCURLOPT_ENCODING'deflate');
    curl_setopt($cCURLOPT_ENCODING'');
    curl_setopt($cCURLOPT_FOLLOWLOCATION1);
    $page curl_exec($c);
    $code explode('country',$page);
    $code explode(':',$code[1]);
    $code explode('admin-c:',$code[1]);
    $country_code=trim($code[0],"admin-c:");
    return 
    $country_code;
    }
    // Detect user's IP address
    $user_ip $_SERVER["REMOTE_ADDR"];

    // COUNTRY CODE, eg. us, fr, vn
    $country_code get_country_code($user_ip);

    switch(
    $country_code)
        {
            case 
    'US':
                
    //redirect to US page            
                
    break;
            case 
    'FR':
                
    //redirect to FR page            
                
    break;
            case 
    'PL':
                
    //redirect to pl page            
                
    break;
    //etc...etc...etc
            
    default:
                
    //default redirect
        
    }


    ?> 
    regards :)
     
    • Thanks Thanks x 1
  6. paperchaser

    paperchaser Guest

    I was going crazy today trying to put together a nice cloak/redirect script for a facebook ad. I came across this, enjoy!

    This snippet originally is used for targetting ad banners depending on the geographic location of the visitor, but can be used for other purposes. Its originally used for the US and the rest of the world, but you can add checks for other countries too.

    PHP:
    <?php
      
    /**
       * Original code from svn://hostip.info/hostip/api/trunk. Optimized & enhanced by Quang Pham @ Saoma, 06.01.07.
       */   
      
    function isPrivateIP($ip) {
        list(
    $a$b$c$d) = sscanf($ip"%d.%d.%d.%d");
        return  
    $a === null || $b === null || $c === null || $d === null ||
                
    $a == 10    ||
                
    $a == 239   ||
                
    $a == 0     ||
                
    $a == 127   ||
               (
    $a == 172 && $b >= 16 && $b <= 31) ||
               (
    $a == 192 && $b == 168);
      }   
       
      function 
    getIP() {
        
    $default false;
       
        if (isset(
    $_SERVER)) {
          
    $default_ip $_SERVER["REMOTE_ADDR"];     
          
    $xforwarded_ip $_SERVER["HTTP_X_FORWARDED_FOR"];
          
    $client_ip $_SERVER["HTTP_CLIENT_IP"];   
        } else {
          
    $default_ip getenv('REMOTE_ADDR');
          
    $xforwarded_ip getenv('HTTP_X_FORWARDED_FOR');
          
    $client_ip getenv('HTTP_CLIENT_IP');
        }
       
        if (
    $xforwarded_ip != "") {
          
    $result $xforwarded_ip;
        } else if (
    $client_ip != "") {
          
    $result $client_ip;
        } else {
          
    $default true;
        }
       
        if (!
    $default) { // additional check for private ip numbers
          
    $default isPrivateIP($result);
        }
       
        if (
    $default) {
          
    $result $default_ip;
        }
       
        return 
    $result;
      }
     
      function 
    showUSContent() {
        
    // show US content here, for ex. Yahoo! ads 
      
    }
     
      function 
    showInternationalContent() {
        
    // show international content here, for ex. Google ads
      
    }
     
      function 
    showGeoTargetContent() {
        
    // make a valid request to the hostip.info API 
        
    $url "http://api.hostip.info/country.php?ip=".getIP();
     
        
    // fetch with curl
        
    $ch curl_init();
     
        
    curl_setopt($chCURLOPT_URL$url);
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    $country curl_exec($ch);
     
        
    curl_close ($ch);
     
        
    // display according geotarget
        
    if ($country == "US") {
          
    showUSContent();
        } else {   
          
    showInternationalContent();
        }
      } 

      
    showGeoTargetContent();
    ?>
     
    • Thanks Thanks x 3
  7. billygood

    billygood Senior Member

    Joined:
    Sep 21, 2008
    Messages:
    941
    Likes Received:
    667
    Occupation:
    marketer
    Location:
    Florida in the winter
    Home Page:
    very very nice.
     
  8. zonez

    zonez Newbie

    Joined:
    Dec 21, 2006
    Messages:
    5
    Likes Received:
    0
    If you are still looking; I have something like this. Complete with admin backend to manage the targets. Icq 208807506
     
  9. neobyte

    neobyte Junior Member

    Joined:
    Sep 15, 2008
    Messages:
    122
    Likes Received:
    16
    There are both free and paid version at maxmind.com. It is pretty comprehensive list.