Use this script to get the two-character country code of the server the user is browsing from.
It needs to be hosted on a web-based server in order to work properly. If you are viewing this on a local server (MAMP, etc.) you will see a value of "XX".
The country code is stored in a cookie to avoid too many api calls. Click here to reset the cookie.
Your two-character country code is:
You can test this functionality using an international proxy server. Be warned, not all proxy servers will return a correct value!
If you open the JavaScript console, it will tell you whether that value was read from the cookie or from the server.
A full list of IP addresses with their locations can be found here.