riskivy / yii2-geoip
Yii 2 GeoIP extension. Returns country, city, lat, lng of current or specified IP (uses MaxMind's GeoIP2 databases)
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: >=5.4.0
- maxmind-db/reader: ~1.0
- yiisoft/yii2: >=2.0.0
Requires (Dev)
- phpunit/phpunit: ~4.4
This package is not auto-updated.
Last update: 2024-12-26 13:50:58 UTC
README
Provides information about geographical location of user by IP address.
Currently available:
- Country
- City
- Latitude, Longitude
- Country ISO Code
Install
Run
$ php composer.phar require riskivy/yii2-geoip "~1.0"
OR
add to your composer.json
{ "require": { "riskivy/yii2-geoip": "~1.0" } }
and run
$ php composer update
Usage
Like component
<?php $config = [ ... 'components' => [ 'geoip' => [ 'class' => 'riskivy\GeoIP\GeoIP', 'dbPath' => Yii::getAlias('@example/maxmind/database/city.mmdb') ], ] ... ];
somewhere in code
$ip = Yii::$app->geoip->ip(); // current user ip $ip = Yii::$app->geoip->ip("208.113.83.165"); $ip->city; // "San Francisco" $ip->country; // "United States" $ip->location->lng; // 37.7898 $ip->location->lat; // -122.3942 $ip->isoCode; // "US"
Like object directly somewhere in your application
$geoip = new \riskivy\GeoIP\GeoIP(); $ip = $geoip->ip("208.113.83.165"); $ip->city; // "San Francisco" $ip->country; // "United States" $ip->location->lng; // 37.7898 $ip->location->lat; // -122.3942 $ip->isoCode; // "US"
FAQ
Q: I get error Required database not available at /usr/share/GeoIP/GeoIPCity.dat.
. What to do?
A: Download this file http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz and ungzip it into /usr/share/GeoIP/GeoIPCity.dat