uses very, very old ip2country database, and so it is very inaccurate.
So, it was unusable for me and I made something with a new database, and I will update database monthly.
It's free for everyone to use, in the same way (good idea)
I appologise for the late reply, but it should help posterity.
Consider ipcountryphp(my site, my code, my honour) as it provides a local internet-lifetime freely updated database. It's fast and fully self-contained, pluggable into anything PHP 5.3, SQLite3 and beyond. Very fast seeks and no performance penalties.
Enough with self-promotion, let's clear something out regarding the other suggestions.
Relying on querying remote services in real-time to get visitor country can become a major bottleneck for your site's functionality depending on the response speed of the queried server. As a rule of thumb you should never query external services for real-time site functionality (like page loading). Using APIs in the background is great but when you need to query the country of each visitor before the page is rendered, you open yourself up to a world of pain.
And do keep in mind you're not the only one abusing free services :)
So queries to 3rd-party services stay in the background while only local functionality that relies on no 3rd-party go into the layers there users interact with. Just my slightly performance paranoid take on this :)
PS: Above mentioned script I wrote has IPv6 support too.
Just so that you're aware, the data for this is massive and it usually comes in csv flavour. Converting it to SQL can be a bit awkward - you'll need to take care of commas in some country names. The CSV is around 4Mb.
As new IP addresses are added all the time, you may need to set up some automated script. BTW - the csv I used was only for IPv4.
Also the csv will hold the integer equivalent of the ip address:
the ip address: a.b.c.d
will give [a*16777216 + b*65536 + c*256 + d] as the "ip decimal number"
If you're in one of those predicaments where cls.__private attributes just aren't enough since they can easily be accessed through inst._cls__private, and you need something a little more secure, here's ...