alkarkhi / useragentgenerator
A Simple and Efficient User Agent Generator for PHP
This package is not auto-updated.
Last update: 2025-04-02 11:49:29 UTC
README
A Simple and Efficient User Agent Generator for PHP.
Features
- Super fast - even for generating 100's of user agents.
- Generates real user agents
- No dependencies
- Native composer support
- Generates user agents for newer browser versions.
- Very easy to add support for newer browser versions.
Installation
Install via composer:
composer require alkarkhi/useragentgenerator
or download the latest release and include UserAgent.php
Examples
To generate a random user agent, use:
require_once __DIR__ . '/vendor/autoload.php'; // If you installed through composer
use Alkarkhi\UserAgentGenerator\UserAgent;
$agent = new UserAgent();
echo $agent->generate();
You can also specify an operating system and/or browser:
require_once __DIR__ . '/vendor/autoload.php';
use Alkarkhi\UserAgentGenerator\UserAgent;
$agent = new UserAgent();
$agent->set_os(["windows"]); // OS must be Windows
$agent->set_browser(["chrome"]); // Browser must be Chrome
echo $agent->generate();
You can specify multiple ones too:
$agent->set_os(["windows", "linux"]);
Options for operating systems are windows
, mac
and linux
Options for browsers are chrome
and firefox
A mac user agent contains the os version. By default it's set to 10.15 (Catalina). If you want to change it, use:
$agent->set_macos_version(12.0); // Monterey
You can generate an array of user agents by passing a parameter to generate()
:
print_r($agent->generate(10)); // Generates 10 user agents
By default, if you leave the parameter blank or pass 1, a string will be returned. To return an array, use:
$agent->set_one_to_string(false);
Comparisons
Speed
Mean time for 10 tries in format: seconds (standard deviation)
user agents generated | campo/random-user-agent | mwhite/random-uagent | chrisspaghetti/useragentgenerator | alkarkhi/useragentgenerator |
---|---|---|---|---|
1 | 0.00204 (0.000886) | 0.000106 (0.0000649) | 0.00015 (0.0000599) | 0.000145 (0.0000441) |
10 | 0.0035 (0.00182) | 0.000368 (0.00017) | 0.00109 (0.000379) | 0.000183 (0.0000506) |
1000 | 0.0509 (0.0228) | 0.0153 (0.00684) | 0.0636 (0.0268) | 0.00390 (0.00164) |
Features
features | campo/random-user-agent | mwhite/random-uagent | chrisspaghetti/useragentgenerator | alkarkhi/useragentgenerator |
---|---|---|---|---|
PSR-4 support | y | n | n | y |
All Real user agents | y | n | y | y |
Browsers supported | Chrome, Firefox, Safari, Opera, IE | Chrome, Firefox, Safari, Opera, IE | Chrome, Firefox, Safari, Opera, IE | Chrome, Firefox |
OS’s supported | Windows, macOS, GNU/Linux, BSD, Android, iOS | Windows, macOS, GNU/Linux | Windows, macOS, GNU/Linux, Android, iOS | Windows, macOS, GNU/Linux |
Supports new browser versions | n | n | n | y |
Last updated | 13/06/18 | 19/02/14 | 01/11/20 | 30/11/21 |
License | MIT | Beer-ware license | GPL-3.0-only | EUPL-1.2 |
TO-DO
- Add support for percentage of times to generate an user agent for browser/os
- Add support for Android and iOS.
- Add support for desktop Safari.
- Add support for Android Chrome, Android Firefox (Fennec) and iOS Safari.
Contributing
If you don't have an account, email mohammed.dev@alkarkhi.com for one.
Submitting bug reports
Please submit bug reports in the issue tracker or email. Before submitting, check that it's not already been reported
Include:
- Library version.
- PHP version.
- Explanation on how the bug occured.
- Any error messages. Check the server logs if they are not displayed on the browser.
Contributing code
- Fork the repository
- Make your changes on the most appropriate branch (
master
most of the time). - Add a unit test in the
`tests/
` directory. - Submit a pull request
FAQ
Why can I only generate Chrome and Firefox user agents?
My criteria for adding a browser are:
- It must use it's own rendering engine.
- It needs to have a reasonable market share.
If you find one that meets all of these criteria, feel free to open a pull request.
For an operating system to be added, it needs to have a reasonable market share.
Contact
Email: mohammed.dev@alkarkhi.com
Donate
Monero: 89YFQGKYhNTWQ7zFU37AzEbEA2E35EdkXcy2ED81N3YtKsEN54ekNJmSue9GAXhffu15tnq9Ym1UW15Nidn7pzY43sZctVu