If your site is behind CloudFlare, you cannot access your visitors IP / Country by using :

echo $_SERVER['REMOTE_ADDR'];

Because it gives you a CloudFlare IP…

Very frustrating if you are trying to block some countries,

Here is the TIP :

<?php
// You can add this code to your header

// display real visitor's IP
// echo "CloudFlare Ip ".$_SERVER["HTTP_CF_CONNECTING_IP"]."<br>"; 

// display real visitor's country code
// echo "CloudFlare Country ".$_SERVER["HTTP_CF_IPCOUNTRY"]."<br>"; 

$country=$_SERVER["HTTP_CF_IPCOUNTRY"];

// Test if visitor is from some countries and redirect them if so
if (($country=='TH') OR ($country=='AF') OR ($country=='PK') OR ($country=='IN') OR ($country=='MM'))
{
   // Display a nice message ;-)
   // echo "pay klai klai !";

   // or redirect this visitor to a nice page
?>
   <script type="text/javascript">
      document.location="https://web-a-way.com";
   </script>
<?php
}
?>

That’s it !

Take a look at https://underthebo.com to see it live,

To discover the full website, you can buy a plane ticket or use a VPN…