alkarkhi/useragentgenerator

A Simple and Efficient User Agent Generator for PHP

1.0.1 2021-11-29 21:16 UTC

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 generatedcampo/random-user-agentmwhite/random-uagentchrisspaghetti/useragentgeneratoralkarkhi/useragentgenerator
10.00204 (0.000886)0.000106 (0.0000649)0.00015 (0.0000599)0.000145 (0.0000441)
100.0035 (0.00182)0.000368 (0.00017)0.00109 (0.000379)0.000183 (0.0000506)
10000.0509 (0.0228)0.0153 (0.00684)0.0636 (0.0268)0.00390 (0.00164)

Features

featurescampo/random-user-agentmwhite/random-uagentchrisspaghetti/useragentgeneratoralkarkhi/useragentgenerator
PSR-4 supportynny
All Real user agentsynyy
Browsers supportedChrome, Firefox, Safari, Opera, IEChrome, Firefox, Safari, Opera, IEChrome, Firefox, Safari, Opera, IEChrome, Firefox
OS’s supportedWindows, macOS, GNU/Linux, BSD, Android, iOSWindows, macOS, GNU/LinuxWindows, macOS, GNU/Linux, Android, iOSWindows, macOS, GNU/Linux
Supports new browser versionsnnny
Last updated13/06/1819/02/1401/11/2030/11/21
LicenseMITBeer-ware licenseGPL-3.0-onlyEUPL-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

License

EUPL-1.2-or-later