admin Level: Administrator

 Registered: 04-04-2002 Posts: 35
|
Geo target function
I've found this interesting function used to check the country for your site's visitors
<?php
function CheckCountry()
{
// make a valid request to the hostip.info API
if ($_SERVER['HTTP_X_FORWARD_FOR']) {
$ip = $_SERVER['HTTP_X_FORWARD_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$url = "http://api.hostip.info/country.php?ip=".$ip;
// fetch with curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$country = curl_exec($ch);
curl_close ($ch);
return $country;
}
?>
|
I've used it to geo-target one of my Ad campaign to canadian users only...
hope you find it useful
____________________________
AndreaVB
|