<?
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
$asia=array("AF","BD","BT","IO","BN","KH","CN","TP","GU","HK","IN","ID","JP","KZ","KP","KR","KG","LA","MO","MY","MV","MN","MM","NR","NP","MP","PK","PW","PH","SG","LK","TJ","TW","TH","TM","SU","UZ","VM");
// Establishing a database connection
$dbh=mysql_connect("localhost","user","pass");
mysql_select_db("country");
// Query for getting visitor countrycode
$country_query = "SELECT country_code2,country_name FROM iptocountry ".
"WHERE IP_FROM<=inet_aton('$REMOTE_ADDR') ".
"AND IP_TO>=inet_aton('$REMOTE_ADDR') ";
// Executing above query
$country_exec = mysql_query($country_query);
// Fetching the record set into an array
$ccode_array=mysql_fetch_array($country_exec);
// getting the country code from the array
$country_code=$ccode_array['country_code2'];
$numElements = count($asia);
for($counter=0; $counter < $numElements; $counter++)
{
if ($country_code==$asia[$counter]) {
header("Location: http://www.google.com/");
}
}
// Closing the database connection
mysql_close($dbh);
?>