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 possible 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.