Get exclusive CAP network offers from top brands

View CAP Offers

Geotag within PHP – Needed

[bsa_pro_ad_space id=2]
  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #784618
    Anonymous
    Inactive

    First of all you’ll need a database of IP addresses and then there are usually examples of its usage (including PHP) on corresponding sites.

    You can get such db for free (without state info) here: http://ip-to-country.webhosting.info/node/view/9 or here: http://www.ip2nation.com/. I personally prefer ip-to-country because it’s updated more regularly and it’s bigger;
    Or paid (with state info and so on) here: http://www.ip2location.com/free.asp (didn’t tried it myself).

    #784656
    triplecrown
    Member

    Here’s exactly how to do it:
    First of all go to the site http://www.maxmind.com and set up an account. once you get a liscense key use the following code to sort your visitors. I do it on a country level separation. Place your license key where it says: YOUR_KEY_GOES_HERE

    [PHP] $ipaddress=$_SERVER;
    $license_key = YOUR_KEY_GOES_HERE;
    $query = “http://geoip1.maxmind.com/a?l=” . $license_key . “&i=” . $ipaddress;
    $url = parse_url($query);
    $host = $url[“host”];
    $path = $url[“path”] . “?” . $url[“query”];
    $timeout = 1;
    $fp = fsockopen ($host, 80, $errno, $errstr, $timeout);
    if ($fp) {
    fputs ($fp, “GET $path HTTP/1.0nHost: ” . $host . “nn”);
    while (!feof($fp)) {
    $buf .= fgets($fp, 128);
    }
    $lines = split(“n”, $buf);
    $country = $lines[count($lines)-1];
    fclose($fp);
    } else {
    # enter error handing code here
    }
    # echo $country;

    ?>[/PHP]

    After executing this code you’ll get the variable $country == “US” or some other country.
    You can then sparse your traffic accordingly. You are limited by your imagination.

    One word of caution though. Don’t cloak your pages. Only vary the banners or redirects. Don’t change the overall content because I think it will trigger a “cloaked” pages penalty if you do it incorrectly.

    Cheers!

    #784691
    Nick Zod
    Member

    may be better use module GEOIP for apache.

    #784726
    jobsoldier
    Member

    Don’t know if you need something big, but you can try OpenX (http://www.openx.org) too, it is totally free of charge. Huge script with lot of options about GEO-targetting

    #784775
    Anonymous
    Inactive

    @WagerX 183600 wrote:

    Here’s exactly how to do it:
    First of all go to the site http://www.maxmind.com and set up an account. once you get a liscense key use the following code to sort your visitors. I do it on a country level separation. Place your license key where it says: YOUR_KEY_GOES_HERE

    [PHP] $ipaddress=$_SERVER;
    $license_key = YOUR_KEY_GOES_HERE;
    $query = “http://geoip1.maxmind.com/a?l=” . $license_key . “&i=” . $ipaddress;
    $url = parse_url($query);
    $host = $url[“host”];
    $path = $url[“path”] . “?” . $url[“query”];
    $timeout = 1;
    $fp = fsockopen ($host, 80, $errno, $errstr, $timeout);
    if ($fp) {
    fputs ($fp, “GET $path HTTP/1.0nHost: ” . $host . “nn”);
    while (!feof($fp)) {
    $buf .= fgets($fp, 128);
    }
    $lines = split(“n”, $buf);
    $country = $lines[count($lines)-1];
    fclose($fp);
    } else {
    # enter error handing code here
    }
    # echo $country;

    ?>[/PHP]

    After executing this code you’ll get the variable $country == “US” or some other country.
    You can then sparse your traffic accordingly. You are limited by your imagination.

    One word of caution though. Don’t cloak your pages. Only vary the banners or redirects. Don’t change the overall content because I think it will trigger a “cloaked” pages penalty if you do it incorrectly.

    Cheers!

    Never knew they offer this as a web service. They have the free GEOIP database for download some place on that site as well so you can import it into your MySQL and do all the queries locally which may be more redundant.

Viewing 5 posts - 1 through 5 (of 5 total)