Ip To Country detection
First grab Geo Lite Country database from Max Mind website. Then grab a small PHP class.
When you have those just write a few lines of code to display country of any visitor of your site.
How to detect user’s country/language – the simple way
To detect user’s language we need a table of language codes and the $_SERVER['HTTP_ACCEPT_LANGUAGE'] variable.
How to detect visitor’s country using his IP address
Software77 is perhaps the first company which created IP to country database. On their website you can grab the DB in CSV and GeoIP format with a few example scripts in various languages to use the DB. I couldn’t find anything in PHP to operate on their GeoIP format DB, so I converted the CSV version to PHP arrays and created a simple script to handle this new format.