An easy free choice is IP2Country database (it uses the free database from MaxMind GeoIP) but free isn't always better. The rest is for you to research.
Or you can just use two lines of code: $geo = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])); $countryCode = $geo['geoplugin_countryCode']; PHP: If your host doesn't support file_get_contents, add _curl to the end of that function and add this function at the top of your script function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } PHP: If you get a ton of traffic, I would recommend assigning cookies to visitors with their country codes so that if they revisit the page/site you can pull that from their cookies before you start pulling it from the geoplugin url. Far as the MaxMind stuff goes, to get country code from it, simply download the latest GeoLite Country binary database from here : http://www.maxmind.com/app/geolitecountry and then download geoip.inc from here http://geolite.maxmind.com/download/geoip/api/php/ Then you use this code (assuming both geoip.inc and GeoIP.dat are in the same folder) include("geoip.inc"); $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD); $addr = $_SERVER["REMOTE_ADDR"]; $country_code = geoip_country_code_by_addr($gi, $addr); geoip_close($gi); PHP: That would be a local way of doing it if you don't want to hit up one of the servers for each request. Far as accuracy goes, country wise its not too big a deal,but city wise you may wish to have more fine tuned accuracy, which maxmind offers the paid database. For example the difference between GeoLite Country and GeoIP Country (paid), is 99.5% accuracy and 99.8%.
there are many websites offering you the service for free like "whatismyipaddress dot com" and many more. If you want to integrate the code in your website, you can follow the code as 'kblessinggr" mentioned, or PM me if you want the code for asp.net There are some 3rd party sites offering this service for web administrators for free like "ewebcounter dot com"
You don't need a whatsmyip service if they're visiting your site since you can get that information right from your webserver.
Using a database that you download means that when things change your information is out of date. Use kblessinggr's method - an API provided by a geolocation site - and your data will usually be current. (It may not be if you check right after there's a change and they haven't changed the database yet, but countries don't just pop up out of nowhere - we usually have months of notice before there's a change, so they're usually up to date.)