Get exclusive CAP network offers from top brands

View CAP Offers

Reply To: Geotag within PHP – Needed

[bsa_pro_ad_space id=2]
#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!