I have a US and UK website. If the user is from the UK, and is on the US website, then show a message on a page to redirect to the correct site. How can I do this?
Detect Country then show message?
283 views Asked by Ernest At
2
There are 2 answers
0
On
One option is to get the IP and use a geo-location lookup as discussed in this thread? Once you know the IP you can get the country and redirect as required.
You can look up the IP in a geo database, such as GeoLite (http://dev.maxmind.com/geoip/legacy/geolite), to figure out where the user is located.
GeoLite databases can be downloaded to your app. Then simply create a small server endpoint to make IP lookups in the database.
Using JavaScript you can then:
Of course you could also do this server-side, and automatically redirect the user if that's your preferred approach.