Yii 1.1: eiptocountry

This extension tries to find the country name and ISO code based on MaxMind's GeoLiteCountry data.

This is an extension to help you determine the country of a visitor based on his/her ip. It does not have the bells and whistles of other Geo oriented extensions currently available here, but it does the job nicely if you just want to know the country of the visitor and nothing else.

It uses a database table instead of over the web connections for reliability and speed. You are advised to update the table on a monthly basis using the data from the original source (http://www.maxmind.com/app/geolitecountry).


You will need to create a database table with the following format:

CREATE TABLE IF NOT EXISTS `geo_countries` (
  `begin_ip` varchar(30) NOT NULL,
  `end_ip` varchar(30) NOT NULL,
  `begin_num` varchar(30) NOT NULL,
  `end_num` varchar(30) NOT NULL,
  `country_iso` char(2) NOT NULL,
  `country_name` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)

and import Maxmind's GeoLiteCountry CSV file into it. You will find the CSV version of it at http://www.maxmind.com/app/geolitecountry. Download the CSV and match the order of the fields with the order of the database table fields above, starting from the begin_ip field.


You might want to use the extension as an application component by adding the following to your config's components section:

Open the extension to change the default country/ISO if necessary. It defaults to UK if it cannot detect the country.

To find out the name of the country, use the following code anywhere necessary:

$visitorCountryName = Yii::app()->location->getCountryName();
$visitorCountryISO = Yii::app()->location->getCountryISO();


  • version 1.0: initial release
  • version 1.1: added default country/ISO to assist local development.


Suggestions/corrections welcomed.


Cassiano Surek - www.surek.co.uk

Be the first person to leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: cass
  • Category: Others
  • Votes: +3
  • Downloaded: 596 times
  • Created on: Oct 10, 2011
  • Last updated: Oct 20, 2011
  • Tags: geolocation