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

  1. Requirements
  2. Usage
  3. ChangeLog
  4. Extra

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).

Requirements

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.

Usage

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();

ChangeLog

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

Extra

Suggestions/corrections welcomed.

Thanks,

Cassiano Surek - www.surek.co.uk

3 0
8 followers
600 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Developed by: cass
Created on: Oct 10, 2011
Last updated: 12 years ago

Downloads

show all

Related Extensions