There are some databases of information for this, most of them have names that make sense, like "ip2country."
So you can just pipe $_SERVER['REMOTE_ADDR'] into them and see what you get back.
There's also a handful of PHP-specific scripts for it, that fetch from local databases or files.