PHPackages                             aknife/agent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. aknife/agent

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aknife/agent
============

获取IP、语言、操作系、浏览器、手机备的名称等

v1.0.0(3y ago)52662MITPHPPHP &gt;=5.6

Since May 30Pushed 3y agoCompare

[ Source](https://github.com/aknife2019/agent)[ Packagist](https://packagist.org/packages/aknife/agent)[ Docs](https://aknife.cn)[ RSS](/packages/aknife-agent/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Agent
=====

[](#agent)

规则更新于 2022年4月28日

安装
--

[](#安装)

使用 composer:

```
composer require aknife/agent
```

### 基础用法

[](#基础用法)

---

```
use Aknife\Agent\Agent;
```

---

### 设置返回的语言

[](#设置返回的语言)

如果未设置，默认调用中文

```
Agent::lang('en'); // zh_cn / zh_tw / en
```

### 解析特定的 header

[](#解析特定的-header)

```
Agent::setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/14G60 UCBrowser/11.7.7.1031 Mobile AliApp(TUnionSDK/0.1.20)');
```

### 解析特定的 IP

[](#解析特定的-ip)

```
Agent::ip('159.75.190.197');
/*
[
    'continent' => [
            'code' => 'AS',
            'name' => '亚洲',
    ],
    'country' => [
            'code' => 'CN',
            'name' => '中国',
    ],
    'region' => '广东省',
    'city' => '广州市',
]
*/
```

### 浏览器的语言

[](#浏览器的语言)

```
Agent::languages(); // return "zh-CN/zh-TW/en-US";
```

### 操作系统

[](#操作系统)

获取操作系统 Windows7 / Windows10 / Mac OS / FreeBSD / Linux，如果是手机，则获取 andorid / iphone /

```
Agent::platform();  //  ['name'=>'Windows','version'=>'10']
```

### 浏览器名称

[](#浏览器名称)

获取浏览器的名称. (谷歌浏览器 / IE 浏览器 / Edge 浏览器 / 苹果浏览器 / 火狐浏览器 / 华为浏览器 / 小米浏览器 / QQ内置浏览器 / 微信内置浏览器 / QQ浏览器 / ...)

```
$browser = Agent::browser(); // [ 'name'=>'Chrome','version'=>'74.0','full'=>'74.0.3729.131' ]
```

### 设备名称

[](#设备名称)

获取设备名称

```
Agent::device();    //  ['model'=>'honor V10','brand'=>'Huawei','category'=>'smartphone']
```

### 机器人名称

[](#机器人名称)

获取机器人名称. (百度蜘蛛 / Curl / Python / Java ...),如果存在验证规则，则判断蜘蛛真假

```
Agent::robot(); // ['name'=>'Baidu Spider','category'=>'Search bot','checked'=>'false']
```

### 其他用法

[](#其他用法)

```
Agent::setIp('8.8.8.8');
Agent::isMobile();
Agent::isMobileApp();
Agent::isTablet();
```

License
-------

[](#license)

Laravel User Agent is licensed under [The MIT License (MIT)](LICENSE).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1449d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/176fe4f4076da44eee3ed401f8d6e80e12f6f6c9eef1d7bd8452d64512cec672?d=identicon)[aknife2019](/maintainers/aknife2019)

---

Top Contributors

[![aknife2019](https://avatars.githubusercontent.com/u/50777910?v=4)](https://github.com/aknife2019 "aknife2019 (19 commits)")

---

Tags

agentphpuseragentuseragentiplocation

### Embed Badge

![Health badge](/badges/aknife-agent/health.svg)

```
[![Health](https://phpackages.com/badges/aknife-agent/health.svg)](https://phpackages.com/packages/aknife-agent)
```

###  Alternatives

[jenssegers/agent

Desktop/mobile user agent parser with support for Laravel, based on Mobiledetect

4.8k67.8M440](/packages/jenssegers-agent)[whichbrowser/parser

Useragent sniffing library for PHP

1.8k11.6M50](/packages/whichbrowser-parser)[foroco/php-browser-detection

Ultra fast PHP library to detect browser, OS, platform and device type by User-Agent parsing

1554.7M7](/packages/foroco-php-browser-detection)[woothee/woothee

Cross-language UserAgent classifier library, PHP implementation

108633.5k4](/packages/woothee-woothee)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
