sablesoft / yii2-geoip
GeoIP component for yii2 application
v1.0.0
2020-07-06 14:29 UTC
Requires
- php: >=7.2
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2026-03-07 03:54:22 UTC
README
Installation
The preferred way to install the geoip is through composer.
Either run
composer require sablesoft/yii2-geoip
or add
"sablesoft/yii2-geoip": "*",
to the require section of your composer.json.
Then add geoip in your app config:
'components' => [ 'geoip' => [ 'class' => 'sablesoft\geoip\GeoIP', 'dbPath' => '/path/to/your/geoip/database' ] ]
How to Use
Use get method to get IP data:
$ip = "52.141.159.163"; /** @var \sablesoft\geoip\IpData $ipData */ $ipData = \Yii::$app->geoip->get($ip); $country = $ipData->countryName; $city = $ipData->cityName; $code = $ipData->countryCode; $default = false; $path = "some.path.in.ip.data.array"; $someData = $ipData->get($path, $default);