geoip Net_GeoIP port for Yii - Get a geographical location given an IP address

  1. Documentation
  2. Change Log

This extension is a port of the Net_GeoIP PEAR package for Yii to get a geographical location given an IP address.

Made some adjustments to make it independent of the PEAR package. Basically it's just a proxy module that uses the library developed ported by Hans Lellelid in the PEAR package.

Resources

Documentation

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

Notes:

Methods lookupOrg and lookupRegion require specific databases (only paid versions available from MaxMind).

Change Log

June 1, 2013
  • Fix usage of non-static method in static context
    July 21, 2010
  • Initial release.
14 0
21 followers
3 533 downloads
Yii Version: 1.1
License: LGPL-3.0
Category: Networking
Developed by: Dinis
Created on: Jul 21, 2010
Last updated: 7 years ago

Downloads

show all

Related Extensions