I have seen websites which managed to restrict visitors if they are from a different country.
To be more clear, example - www.domainName.uk and then there is also a www.domainName.th, so if I am in UK and then I want to browse the site at th, I can’t.
As I am exploring something like that, how do I make that happen in my site ?
Do I need to configure the server or I must do it programmtically but how ?
Hope someone can share with me some tips.
Get the user’s IP address.
Using this IP address, perform an IP Geocoding.
There are lots of sites that offer this API access. like this https://ipstack.com/
Call the API, passing the user’s IP address as a parameter.
You’ll get a response giving you all the details about that IP address.
continent_name: “North America”
country_name: “United States”
Check the region or the country code, and reroute user to the appropriate page or website.
NOTE: The Geocoding result may not be accurate, because it’s a guesstimate on whose Internet company that IP address block is assigned to. If your ISP is in another city different from yours, Geocoding your IP will display the ISP’s city, not yours. But for your purpose, that’s good enough.