Blocking unwanted countries by a php code

Owning a network of proxies I was always meddling around trying to find ways to decrease the bandwidth usage on my sites. Then I came across GeoIP. Simply placing two files(geoip.dat and geoip.inc) in the same folder that contains index.inc.php, and then adding a snippet of code to the top of your main index file(in this case index.inc.php if your a proxy webmaster) file you can limit which countries are able to view your proxies. You can also redirect them to a site of your choice. This can be useful if you are currently smart priced by Google, as only allowing English speaking countries to view your ads will increase the conversion rate, and after a couple weeks you won’t be smart priced anymore. Another option is to start a site that holds other CPC ads on it other than adsense, and redirect all foreign traffic to this site. Below is the code to place at the top of your index.inc.php file:

<?php

// This code demonstrates how to lookup the country by IP Address

include(”geoip.inc”);

// Uncomment if querying against GeoIP/Lite City.
// include(”geoip.inc”);

$gi = geoip_open(”geoip.dat”,GEOIP_STANDARD);

// get the ip of the visitor
$addr = getenv(”REMOTE_ADDR”);
// translate his ip to a country code
$country = geoip_country_name_by_addr($gi, $addr);
// close the geo database
geoip_close($gi);

$okcountry = array(”United States”, “United Kingdom”, “Canada”, “Australia”);

// redirect them if they suck
if(!in_array($country, $okcountry))
header(’Location: http://www.joinlist.info/’)

?>


Source: http://www.samdaves.com/blog/?s=geoip

Leave a comment

Your comment