Cloaking only U.S. Visitors

  • Thread starter Thread starter paperchaser
  • Start date Start date
P

paperchaser

Guest
Just wondering if its possible to cloak via geographical location?

I need to show one version of the site to US visitors, and the real version of the site to all other visitors.

Is this possible? Any help is greatly appreciated, thanks!
 
Yup, that's possible, simply download the ip-to-country database here

Code:
http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip

and manipulate the data to retrieve all US IPs. Once you have the list of IPs, you can just input them into your cloaker's IP list.

PS. Handbook for the database can be found here

Code:
http://ip-to-country.webhosting.info/node/view/12
 
You can easily do it on the fly using a bit of PHP, if your hosting accepts fopen (I can do it a different way if needed):

PHP:
<?php
    $user_ip = $_SERVER["REMOTE_ADDR"];
    $handle_cc = fopen("http://maychu.net/ip/code/".$user_ip, 'r'); 
    $country_code = fgets($handle_cc, 128); 
    fclose($handle_cc);

    switch($country_code)
    {
        case "US":        header("Location: http://Your_American_page");
                              break;

      default:              header("Location: http://Where_the_rest_of_the_visitors_go");
                              break;
}


?>

That should do ya!
 
keep some way of recording false entries in those DBs. IPs change around quite a bit and no list is ever perfect. On the whole they work well though ;)
 
http://www.hostip.info/ has a SQL database of IP->location you can download for free which is updated daily. I would definitely recommend a local database lookup as opposed to connecting to a remote site as it will be significantly faster and wont be relying on a 3rd party's stability.



This site: http://www.maxmind.com/app/products
also has some very reasonable prices increasing with the specificity of the queries. It's only $50/site license if you just want the country.
 
Last edited:
I use maxmind with the Lite DB which is free and it's quite accurate. I think they say something like 99.5% and you can update your db monthly on the 1st of the month at the same url below. I just use a cron job to wget the file, and unpack it into place on the 2nd of the month to be up to date.

First grab the binary GeoLiteIP country db from here:

Code:
#Site URL
http://www.maxmind.com/app/geolitecountry
Direct Link to Binary DB
http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

Then grab the php functions required:
Code:
http://geolite.maxmind.com/download/geoip/api/php/geoip.inc

So not you have a file called geoip.inc which has all the functions and when unzipped you have GeoIP.dat which is the binary db. Simply shove those onto your web server and use this for your index.php. The below handles Canada, U.S. and U.K but can be expanded to handle any country very easily.

PHP:
<?php


include("geoip.inc");


$ip=$_SERVER['REMOTE_ADDR'];

$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);



// Uncomment if you want country code
//$country_code = geoip_country_code_by_addr($gi, "$ip");



// Get Country Code based on source IP
$country = geoip_country_name_by_addr($gi, "$ip");


/* For testing which country uncomment next line
and it will display the country and then simply add
a case statement for that country
*/

//echo "Country is: $country";



switch($country)
    {
        case "United States":        header("Location: http://Your_American_page");
                              break;
        case "Canada":
                          header("Location: http://Your_Canadian_Page");
                              break;
        case "United Kingdom":
                          header("Location: http://Your_U.K._Page");
                              break;

      default:              header("Location: http://Where_the_rest_of_the_visitors_go");
                              break;
}

geoip_close($gi);

?>

Hope this helps out someone and much as this forum is helping me!
 
Back
Top