- This topic is empty.
-
AuthorPosts
-
October 29, 2008 at 6:40 pm #784618
Anonymous
InactiveFirst 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).October 30, 2008 at 1:02 am #784656
triplecrownMemberHere’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!
October 30, 2008 at 6:14 am #784691
Nick ZodMembermay be better use module GEOIP for apache.
October 30, 2008 at 9:54 am #784726
jobsoldierMemberDon’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
October 30, 2008 at 3:30 pm #784775Anonymous
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.
-
AuthorPosts