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` ( `id` int(11) NOT NULL AUTO_INCREMENT, `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`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=153684 ;
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:
'location'=>array( 'class'=>'ext.iptocountry.EIpToCountry', ), 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();
Cassiano Surek - www.surek.co.uk