Building a server-side geolocation module, I was wondering what were the general view and best practices regarding this. I don't need something very precise as geolocation is concerned, I only need the cc/ll pair so I can redirect the user to the appropriate version of the website.
Currently, the logic behind what I built is the following:
- Check for cookie with country & language info, if unset move to #2.
- Check for session variables for country & language, if unset move to #3.
- Make an IP based query to an external web-service that determines the country; determine the prevalent language for that country from a list. If this fails, try #4.
- Check the
Accept-Language
header from the http request, try and determine the cc/ll pair from there. If inexistent or incomplete (i.e. only language specified: en instead of en-US), fallback to #5. - Go to us/en :).
After a succesful hit to a country version, the cookie and session variables are set to that country/language pair.
Now, two questions:
Would it be better, from a user-experience point of view, to try and combine the data from the webservice (the country) with the header (the language)? I could end up with stuff like fr/en, that doesn't have a corresponding version on the site. I'd have, for every combination that doesn't exist, to point the user to a country-chooser and set the cookie and session to his choice. This would be repeated every time the cookie is clear or expires.
How would you do it? Are there any other sources for this kind of information that I am ignoring?
Thanks :).