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?
Asked
Active
Viewed 202 times
2 Answers
0
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:
- Grab the IP of the current user
- Look up the location in the GeoLite database through the server endpoint
- If in UK on US site (or vice versa) -> display message and optionally redirect the user to the correct website
Of course you could also do this server-side, and automatically redirect the user if that's your preferred approach.

Ted Nyberg
- 7,001
- 7
- 41
- 72