I have an e-commerce site and I'd like to check which country a user is from. Based on his country, the catalog contents will change. I am using PHP as the server-side scripting language. One way to approach this could be to follow the steps at http://de77.com/php/how-to-detect-users-countrylanguage-the-simple-way
Another way would be to let the user choose his country at the time of registration. Then, when he logs in, he will only see products related to his country.
Any other poss开发者_JAVA技巧ible solutions?
The typical way is to detect the user's country based on his IP address. maxmind.com provide a decent free database for this.
As Blair McMillan said, ensure that the user can change their country manually if your auto detection fails for one reason or another.
I would advise using the URL, rather than a cookie, to remember the user's country selection. So, if the user visits the site at a URL without a country code in it, redirect them to site.com/countrycode/. This means that user X can share a link to a product only sold in his country without users of other countries being falsely redirected.
Do a combination. Guess the users country based on their IP and prompt them in some way saying something like: "We think you are location in xxx. If this is wrong, then please select your location". Make sure that you save this value in a cookie so that non-registered used don't keep being asked all the time. Also make sure that the user can change their location.
精彩评论