Cloudflare is great! We must have to admit it to it. What Cloudflare has done to the internet is equally appreciatable as another big technology like facebook and google has done in the last 1-2 decades.
We will here learn, how can we utilize Cloudflare technology to know the user's location and do the action based on it.
If you have CMS or App coded in "PHP ", your best bet is to use header information sent by Cloudflare and get the user's country location from it. Just a line of code and it gets your job done.
Note: Cloudflare only shares 2 character country ISO code, like the US for the USA, IN for India, AU for Australia and other, you can google the 2 digit country code.
<?php $country = $_SERVER['HTTP_CF_IPCOUNTRY']; ?>
your $country has now a country code of your visitors and now, you can do the rest of the logic "switch" or "if else if else" to do your rest of the magic.
Well, that was easy, right?
But, what if your CMS or App is not in PHP language, you can still get the information via header!
But what! what If I don't have server access and my CMS or App is built upon SAAS product like "wix.com", "shopify.com", "Godaddy web builder" or other related products?
Well, here is country detecting code solution for SAAS platform like "wix.com", "shopify.com", "Godaddy web builder" or any other related platforms!
Let's understand, what is happening above in below points.
That is all. Well, hope you find this code useful in your project, we wish you all the best for your job and for any request, you need to get done! you can definitely hire some of the best freelancers in our Marketplace.
I am Full Stack Programmer and Engineer. I develop web apps, mobile apps at the best price. My skills are listed at below section. I also write sometimes blog about various tech stacks. Feel free to follow me on my social media channels listed below.
From: Jaipur, Rajasthan India - Last Login: 3 weeks ago.
0 out of 5
0 out of 5