mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-04 16:01:35 +08:00
32 lines
531 B
PHP
32 lines
531 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use WhichBrowser\Parser as BrowserParser;
|
|
|
|
trait Client
|
|
{
|
|
|
|
public function getClientIp()
|
|
{
|
|
$clientIp = $this->request->getClientAddress();
|
|
|
|
return $clientIp;
|
|
}
|
|
|
|
public function getClientType()
|
|
{
|
|
$userAgent = $this->request->getServer('HTTP_USER_AGENT');
|
|
|
|
$result = new BrowserParser($userAgent);
|
|
|
|
$clientType = 'desktop';
|
|
|
|
if ($result->isMobile()) {
|
|
$clientType = 'mobile';
|
|
}
|
|
|
|
return $clientType;
|
|
}
|
|
|
|
} |