I need to show different links for US and non-US visitors to my site. This is for convenience only, so I am not looking for a super-high degree of accuracy, and security or spoofing are not a concern.
I know there are geotargeting services and lists, but this seems like overkill since I only need to determine (roughly) if the person is in the US or not.
I was thinking about using JavaScript to get the user's timezone, but this appears to only give the offset, so users in Canada, Mexico, and South America would have the same value as people in the US.
Are there any other bits of information available either in JavaScript, or PHP, short of grabbing the IP address and doing a lookup, to determine this?
@rostislav
or using cURL:
Depending on which countries you want to distinguish, time zones can be a very easy way to achieve it - and I assume it's quite reliable as most people will have the clocks on their computers set right. (Though of course there are many countries you can't distinguish using this technique).
Here's a really simple example of how to do it:
http://unmissabletokyo.com/country-detector
My solution, easy and small, in this example i test Canada region from language
fr-CA or en-CA
There are some free services out there that let you make country and ip-based geolocalization from the client-side.
I've used the wipmania free JSONP service, it's really simple to use:
Or if you use a framework that supports JSONP, like jQuery you can:
Check the above snippet running here.
The best indicator is probably the HTTP Accept-Language header. It will look something like below in the HTTP request:
You should be able to retrieve this in PHP using the following:
Wipmania.com & PHP