PHPackages                             campo/random-user-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. campo/random-user-agent

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

campo/random-user-agent
=======================

Generate real random user-agents.

1.3.0(7y ago)1451.2M↓14.2%2420MITPHPPHP &gt;=5.3.0

Since Oct 5Pushed 7y ago5 watchersCompare

[ Source](https://github.com/joecampo/random-user-agent)[ Packagist](https://packagist.org/packages/campo/random-user-agent)[ RSS](/packages/campo-random-user-agent/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (20)

random-user-agent
=================

[](#random-user-agent)

[![Latest Version on Packagist](https://camo.githubusercontent.com/10d811dcd5c94e0ba6d63bce792238913f61d55711289385def76ec8f6bc0e70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63616d706f2f72616e646f6d2d757365722d6167656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/campo/random-user-agent)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Generate real random user-agents. The user agent list is largely pulled from the Firefox extension [random-agent-spoofer](https://addons.mozilla.org/en-US/firefox/addon/random-agent-spoofer/) h/t [dillbyrne/random-agent-spoofer](https://github.com/dillbyrne/random-agent-spoofer). Additional entries were sourced from [UserAgentString.com](http://www.useragentstring.com/) and [WiiBrew](http://wiibrew.org/wiki/User_agents) to provide more options for consoles and common web crawlers

You should be running at least PHP 5.4 to use this class

Install
-------

[](#install)

Via Composer

```
$ composer require campo/random-user-agent
```

Usage
-----

[](#usage)

### Generating a User Agent

[](#generating-a-user-agent)

To generate a random user agent, you can simply use the following:

```
echo \Campo\UserAgent::random(), "\n";
```

### Filtering the Type of User Agent

[](#filtering-the-type-of-user-agent)

To limit the types of user agents that are returned, you can pass a filter array to random():

```
echo \Campo\UserAgent::random([
    'os_type' => 'Windows',
    'device_type' => 'Mobile'
]), "\n";
```

A filter is simply an array with key-value pairs specifying the types of agent strings that you want to have returned. The types of keys in this filtered array may include the following:

- `agent_name`
- `agent_type`
- `device_type`
- `os_name`
- `os_type`

Filters also support passing additional arrays to better segment the results you will receive from random():

```
echo \Campo\UserAgent::random([
    'os_type' => ['Android', 'iOS'],
    'device_type' => ['Mobile', 'Tablet']
]), "\n";
```

The above will return only user-agent’s for Android &amp; iOS OS types that are either mobile or tablets.

To get a list of values that can be accepted by these filter fields, you can use the following methods which will return arrays of values that can be used with the respected fields noted above:

- `UserAgent::getDeviceTypes()`
- `UserAgent::getAgentTypes()`
- `UserAgent::getAgentNames()`
- `UserAgent::getOSTypes()`
- `UserAgent::getOSNames()`

Values passed to filters are case-insensitive

### Error Handling

[](#error-handling)

This class will throw an exception if either a filter returns no user agent strings, which means that a filter was invalid or too specific, or if one of the fields above was not present, which means that this library has been corrupted.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity55

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 69.2% 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

Every ~245 days

Total

5

Last Release

2896d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dafd56686be05c299f7a27d83fb6fb6b277f8efc62d563632fa93706f16a426f?d=identicon)[campo](/maintainers/campo)

---

Top Contributors

[![joecampo](https://avatars.githubusercontent.com/u/3619398?v=4)](https://github.com/joecampo "joecampo (9 commits)")[![nick-andren](https://avatars.githubusercontent.com/u/8352269?v=4)](https://github.com/nick-andren "nick-andren (2 commits)")[![badalsurana](https://avatars.githubusercontent.com/u/3035708?v=4)](https://github.com/badalsurana "badalsurana (1 commits)")[![deminy](https://avatars.githubusercontent.com/u/865547?v=4)](https://github.com/deminy "deminy (1 commits)")

---

Tags

user agentuser agentsspoofing user

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/campo-random-user-agent/health.svg)

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

###  Alternatives

[jenssegers/agent

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

4.8k67.8M440](/packages/jenssegers-agent)[hisorange/browser-detect

Browser &amp; Mobile detection package for Laravel.

1.1k10.1M50](/packages/hisorange-browser-detect)[cbschuld/browser.php

A PHP Class to detect a user's Browser. This encapsulation provides a breakdown of the browser and the version of the browser using the browser's user-agent string. This is not a guaranteed solution but provides an overall accurate way to detect what browser a user is using.

5876.7M19](/packages/cbschuld-browserphp)[jaybizzle/laravel-crawler-detect

A Laravel package to detect web crawlers via the user agent

3232.6M17](/packages/jaybizzle-laravel-crawler-detect)[garetjax/phpbrowscap

Standalone replacement for php's native get\_browser() function

437862.4k5](/packages/garetjax-phpbrowscap)[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)

PHPackages © 2026

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