asinka-studio / php-user-agent-generator
PHP User-agent generator
Package info
github.com/asinka-studio/php-user-agent-generator
pkg:composer/asinka-studio/php-user-agent-generator
0.1.2
2026-02-27 08:18 UTC
Requires (Dev)
- phpunit/phpunit: ^11.0
README
Generate realistic desktop User-Agent strings for modern browsers.
Current Version
- Package version:
0.1.1 - Namespace:
Asinka - Main API:
Asinka\UAGenerator::randomAgent()
Update in 0.1.1
This release adds new functionality on top of previous versions.
- User-Agent generator now supports mobile platforms (
AndroidandiOS). - Added full HTTP headers generator for top-level HTML document navigation.
New headers API (0.1.1)
<?php use Asinka\Headers\DocumentHeadersGenerator; require __DIR__ . '/vendor/autoload.php'; $generator = new DocumentHeadersGenerator(); // Random browser/platform profile $headers = $generator->generateHeaders(); // Explicit profile $headersChromiumWindows = $generator->generateHeaders('chromium', 'Windows');
Update in 0.1.0
1) Updated User-Agent versions and formats
The generator now uses modern UA patterns and version ranges:
Chrome(Chromium-style UA)Edge(Edg/...)Firefox(modernrv+Gecko/20100101format)Safari(macOS Safari format)Opera(OPR/..., Chromium-based)
It also uses current desktop platform tokens:
- Windows 10 style:
Windows NT 10.0; Win64; x64/WOW64 - macOS style:
Mac OS X 13_x,14_x,15_x - Linux style:
X11; Linux x86_64
2) Switched naming from snake_case to camelCase
Public API naming is now camelCase:
- Old:
random_agent(...) - New:
randomAgent(...)
3) Methods are now static
You no longer need to instantiate the class.
- Old:
$generator = new \Asinka\UAGenerator(); $ua = $generator->randomAgent();
- New:
$ua = \Asinka\UAGenerator::randomAgent();
4) Added custom exception
The library now provides and uses its own exception class:
Asinka\Exceptions\UAGeneratorException
The main generator method can throw this exception for invalid or unsupported runtime cases.
Usage
<?php use Asinka\UAGenerator; use Asinka\Exceptions\UAGeneratorException; require __DIR__ . '/vendor/autoload.php'; try { $randomUa = UAGenerator::randomAgent(); $chromeOnWindows = UAGenerator::randomAgent( UAGenerator::BROWSER_CHROME, UAGenerator::OS_WINDOWS ); echo $randomUa . PHP_EOL; echo $chromeOnWindows . PHP_EOL; } catch (UAGeneratorException $e) { echo $e->getMessage() . PHP_EOL; }
Available Constants
Browsers
UAGenerator::BROWSER_CHROMEUAGenerator::BROWSER_EDGEUAGenerator::BROWSER_FIREFOXUAGenerator::BROWSER_SAFARIUAGenerator::BROWSER_OPERAUAGenerator::BROWSER_IEXPLORER(kept for backward compatibility and mapped to modern Edge behavior)
Operating Systems
UAGenerator::OS_WINDOWSUAGenerator::OS_MACUAGenerator::OS_LINUX
Migration Notes
If you are upgrading from an older version:
- Replace
random_agent(...)withrandomAgent(...). - Replace object calls with static calls:
- from
$generator->randomAgent(...) - to
UAGenerator::randomAgent(...)
- from
- Update exception handling to catch
UAGeneratorExceptionwhere needed.