sablesoft / yii2-geoip
GeoIP component for yii2 application
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.2
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2025-03-07 01:12:54 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);