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


Because it gives you a CloudFlare IP…

Very frustrating if you are trying to block some countries,

Here is the TIP :

// 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>"; 


// 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">

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…