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

What geo-targeting script are they using?

Discussion in 'PHP & Perl' started by loophole, Jan 6, 2009.

  1. loophole

    loophole Registered Member

    Joined:
    Apr 7, 2008
    Messages:
    91
    Likes Received:
    82
    I'd like to set up a geotargeting script to insert country names in the sales letter based on IP address, like on
    Code:
    internetmilliondollars.com
    Anybody knows what script that site is using?
     
  2. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    If you just want a country, this is how I get ISO 2 letter country codes with php. ie US, UK, CA etc... Displaying full country names would require a little more coding to convert them.

    -Get the php class for whois queries here:
    Code:
    http://sourceforge.net/projects/phpwhois/
    -Download and decompress into your web root folder.

    -Use something like this on your site:
    PHP:
    <?php
    // Include PHPWhois libs
    include('phpwhois/whois.main.php');
    include(
    'phpwhois/whois.ip.lib.php');
    include(
    'phpwhois/whois.ip.php');

    // Figure out the client's IP
    $ip $_SERVER['REMOTE_ADDR'];

    // Perform the IP whois query
    $whois = new Whois();
    $result $whois->Lookup($ip,false);

    $country_code $result['regrinfo']['owner']['address']['country'];
    echo 
    $country_code;  // Will output 'CA', 'US' or wherever visitor is from
    ?>
    I imagine full country names can also be obtained using mod_geoip for apache, but in my experience its not installed by default on most web hosts. Using mod_geoip is more accurate then the php only method above (you can get city and state I believe). Just goog mod_geoip for more info.

    Hope it helps.
     
    • Thanks Thanks x 1
  3. loophole

    loophole Registered Member

    Joined:
    Apr 7, 2008
    Messages:
    91
    Likes Received:
    82
    Grizzy,

    I am no coding expert. I was thinking there's a simpler script I can install in same fashion as butterfly marke*ting or other membership/minisite scripts.

    I'll check with you later on when I need to implement this.

    Btw, do you have a site where you are using this script of yours?
     
  4. Grizzy

    Grizzy Senior Member

    Joined:
    Nov 11, 2008
    Messages:
    919
    Likes Received:
    999
    Sorry i'm not to familiar with bfly marketing, but im sure you are right and there is a similar script out there. There is probably also a better way to do this in a different language.(or even in php?)

    Actually I use this when I scan my proxies to get a country code, and not on a particular web site I own (but its the same principle).

    If you want to use this I realize I forgot to add a little fix at the end needed to parse the country code from different structures of whois respones.

    PHP:
    <?php

    // Include PHPWhois libs
    include('phpwhois/whois.main.php');
    include(
    'phpwhois/whois.ip.lib.php');
    include(
    'phpwhois/whois.ip.php');

    // Figure out the client's IP
    $ip $_SERVER['REMOTE_ADDR'];

    // Perform the IP whois query
    $whois = new Whois();
    $result $whois->Lookup($ip,false);

    // Parse the country code
    $country_code $result['regrinfo']['owner']['address']['country'];
    $country_code $result['regrinfo']['owner']['address'];
    if (
    strlen($country_code) != 2)
    {
        
    $country_code $result['regrinfo']['owner']['address']['country'];
        if (
    strlen($country_code) != 2)
        {
            
    $country_code $result['regrinfo']['owner']['address'][1];
            if (
    strlen($country_code) != 2)
            {
                
    $country_code $result['regrinfo']['owner']['address'][2];
                if (
    strlen($country_code) != 2)
                {
                    
    $country_code $result['regrinfo']['network']['country'];
                }
            }
        }
    }

    echo 
    $country_code;  // Will output 'CA', 'US' or wherever visitor is from

    ?>
    Hey just hit me up if you need help with it or have any problems at all.

    Good luck.
     
  5. raj564

    raj564 Regular Member

    Joined:
    Dec 6, 2007
    Messages:
    317
    Likes Received:
    93
    Location:
    maxmind offers a free geoip db. perhaps that could help?
     
  6. Barbacamanitu

    Barbacamanitu Jr. VIP Jr. VIP Premium Member

    Joined:
    May 8, 2008
    Messages:
    500
    Likes Received:
    91
    yeah, go with the maxmind one. I can provide a full example of how to use the Binary format one if you need it.
     
  7. iamsgf

    iamsgf Regular Member

    Joined:
    Oct 6, 2008
    Messages:
    307
    Likes Received:
    268
    I as just looking at the maxmind site, however I dont see where they offer the free DB. could you point me in the right direction.

    Thanks
     
  8. emgxxg

    emgxxg Registered Member

    Joined:
    Nov 3, 2008
    Messages:
    93
    Likes Received:
    523
    here you go:
    Code:
    http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/
    that is the db, you'll hvae o figure out the code, though it isn't at all complicated to do so :)

    Cheers!!
     
    • Thanks Thanks x 1
  9. iamsgf

    iamsgf Regular Member

    Joined:
    Oct 6, 2008
    Messages:
    307
    Likes Received:
    268
    Mucho Grasias!!!
     
  10. zone69

    zone69 Junior Member

    Joined:
    Nov 24, 2008
    Messages:
    196
    Likes Received:
    1,290
  11. trophaeum

    trophaeum Senior Member

    Joined:
    Dec 21, 2007
    Messages:
    1,189
    Likes Received:
    706
    If your doing this to try to increase conversions etc you should really look into the paid version of this database as it is far more accurate (take this from someone who has compared the 2 and owns it)
     
  12. kaizersuzi

    kaizersuzi Junior Member

    Joined:
    Dec 31, 2008
    Messages:
    107
    Likes Received:
    132
    Location:
    Next Door2U
    I was also looking for a geotargeting tool. In addition, to maxmind's free tool, I found this plugin for wordpress:
    Code:
    http://www.spoffle.com/technical/geotarget-wordpress-plugin/
     
  13. kaizersuzi

    kaizersuzi Junior Member

    Joined:
    Dec 31, 2008
    Messages:
    107
    Likes Received:
    132
    Location:
    Next Door2U
    Although maxmind says that the free tool is inaccurate. Some long term users confirm that it was not accurate when geotargeting cities and towns. But reported that the free version was fine when geotargeting countries.