0

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?

Ernest
  • 98
  • 7

2 Answers2

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:

  1. Grab the IP of the current user
  2. Look up the location in the GeoLite database through the server endpoint
  3. 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
0

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.

Community
  • 1
  • 1
Tikeb
  • 978
  • 3
  • 9
  • 25