<?php

$continentSites=array(
	'eur' => array(),
	'usa' => array(),
	'asia' => array(),
	'africa' => array()
);


$continentCountries=array(
	'eur' => array('AT','AX','AL','AD','AM','BY','BE','BG','BA','VA','GB','HU','DE','GG','GI','GR','DK','JE','EU','IE','IS','ES','IT','CY','LV','LT','LI','LU','MK','MT','MD','MC','NL','PL','PT','RO','SM','RS','SK','SI','UA','FO','FR','HR','ME','CZ','CH','SE','SJ','EE','FI','IM','NO','AU','AZ','AF','BD','BH','IO','BT','GE','IL','JO','IQ','IR','YE','KZ','QA','KG','KW','LB','MN','PS','RU','SA','SY','TJ','UZ','TM','TR','LK','HM','FJ','WF','TV','TO','SB','WS','PK','NF','CK','OM','AE','NC','NZ','NU','NP','MM','MH','MV','CC','IN','GU','VU',),
	
	
	'usa' => array('AS','AG','AR','AW','BS','BB','BZ','BM','BO','BQ','BR','BF','VE','UM','HT','GY','GP','GT','GF','HN','GD','GL','DM','DO','KY','CA','CO','CR','CU','CW','MQ','MX','NR','NI','PN','SH','PA','PY','PE','PR','SV','BL','MF','PM','VC','KN','LC','SX','SR','US','TZ','TC','TT','UY','FK','CL','GS','AI','VG','MS','JM','EC'),
	
	'asia' => array('PF','JP','PH','TH','SG','MP','KR','PG','PW','CX','FM','MY','MO','LA','CN','KP','TW','KH','ID','HK','VN','TL','BN'),
	
	
	'africa' => array('AO','BW','BI','GA','GM','GH','GN','GW','CD','ZM','ZW','CM','KE','KM','CI','LS','LR','MU','MR','MG','YT','MW','ML','MZ','NA','NE','NG','CG','RE','RW','ST','SZ','SN','SO','SL','TG','TK','UG','TN','CF','TD','GQ','ER','ET','ZA','SS','DZ','AQ','BJ','DJ','EG','EH','CV','LY','MA','TF','SC','BV')
);

$country=isset($_SERVER['HTTP_CF_IPCOUNTRY'])?$_SERVER['HTTP_CF_IPCOUNTRY']:(isset($_SERVER['GEOIP_COUNTRY_CODE'])?$_SERVER['GEOIP_COUNTRY_CODE']:false);
$continent=false;
if ($country!==false) {
	foreach ($continentCountries as $c => $countries) {
		if (in_array($country,$countries)) {
			$continent=$c;
			break;
		}
	}
	if ($continent!==false) {
		$site=$_SERVER['SERVER_NAME'].substr($_SERVER['REQUEST_URI'],0, strrpos($_SERVER['REQUEST_URI'], '/'));
		if (count($continentSites[$continent])>0 && !in_array('http://'.$site,$continentSites[$continent]) && !in_array('https://'.$site,$continentSites[$continent])) {
			header("location: {$continentSites[$continent][0]}/".(count($_GET)>0?'?'.http_build_query($_GET):''));
		}
	}
}
?>