pendalf89 / yii2-clientinfo
Yii2 client info component, that detects real client IP address and device type
Installs: 40
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- mobiledetect/mobiledetectlib: ^4.8
- yiisoft/yii2: ^2.0
README
The component provides a convenient way to retrieve information from the client (user), including the IP address, country, and device. It's very fast thanks to caching. Mobile Detect library is used to determine the type of device. The Sypex Geo database is used to determine the country by IP address.
Installation
The preferred way to install this extension is through composer.
Either run
composer require pendalf89/yii2-clientinfo
or add
"pendalf89/yii2-clientinfo": "^1.0.0"
to the require section of your composer.json
file.
Configuration
'components' => [ 'clientInfo' => 'pendalf89\clientinfo\ClientInfo', ],
You also can add DocBlock into Yii.php
file for IDE autocompleting.
/** * Class WebApplication * Include only Web application related components here * * @property pendalf89\clientinfo\ClientInfo $clientInfo */ class WebApplication extends yii\web\Application { }
Usage
It's very easy to use:
$isMobile = Yii::$app->clientInfo->isMobile(); $ip = Yii::$app->clientInfo->getIP(); $country = Yii::$app->clientInfo->getCountry(); $isFinland = Yii::$app->clientInfo->isCountry('FI');