You could also just ask the visitors to select their country from a list. I reckon about 95% of them will actually do this truthfully. There are complete country lists on the net. I got mine off the net and inserted it into <option> tags. The list I used is at http://www.nationsonline.org. Don't use the UN list because it only includes nations recognised by the UN (e.g. not Palestine).
Of course, this is a no-tech solution and therefore not terribly interesting, but it was my very first exercise in PHP to dynamically generate a country list in a <select> field and pass the chosen value onto a processing script.
Best o luck
Norm