Skip to content

InstallationAndUsage

dlage edited this page Jun 1, 2013 · 1 revision
  1. summary Installation and Usage instructions

Requirements

  • Yii 1.0 or above (tested with Yii 1.1.3 but should work with previous versions)

Installation

  • Extract the release file under `protected/extensions`
  • Change main.php configuration file
  'components' => array(
      ...
      'geoip' => array(
          'class' => 'application.extensions.geoip.CGeoIP',
          // specify filename location for the corresponding database
          'filename' => 'C:\path\to\GeoIP\GeoLiteCity.dat',
          // Choose MEMORY_CACHE or STANDARD mode
          'mode' => 'STANDARD',
      ),
      ...
  ),

Usage

See the following code example:

  $location = Yii::app()->geoip->lookupLocation();
  // with IP in google.com
  $location = Yii::app()->geoip->lookupLocation('209.85.135.104');
  $countryCode = Yii::app()->geoip->lookupCountryCode();
  $countryName = Yii::app()->geoip->lookupCountryName();
  $org = Yii::app()->geoip->lookupOrg();
  $regionCode = Yii::app()->geoip->lookupRegion();

  // Location attributes:
  $location->countryCode
  $location->countryCode3
  $location->countryName
  $location->region
  $location->regionName
  $location->city
  $location->postalCode
  $location->latitude
  $location->longitude
  $location->areaCode
  $location->dmaCode
Clone this wiki locally