PHP: Country Name from IP Address

Here’s a PHP script that demonstrates an easy way to get a country name or code from IP address using pure PHP.

Included in the file:

GeoIP.dat: a binary databases of countries and IPs maintained by MaxMind.com. The database is updated monthly and has a 99.5% accuracy rate. You can always get the latest version here.

geoip.inc & sample.php: The PHP script.

Download: php-ip-to-country.zip ~ 627KB

Leave a Reply

Your email address will not be published. Required fields are marked *