Skip to content

A PHP library to generate over 5 trillion unique, realistic user agents for desktop and mobile devices. Supports browsers like Chrome, Firefox, and Safari, and devices including Android, iPhone, iPad, and iPod.

License

Notifications You must be signed in to change notification settings

tuberboy/useragent-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

UserAgent Generator

A PHP library to generate over 5 trillion unique, realistic user agents for desktop and mobile devices. Supports browsers like Chrome, Firefox, and Safari, and devices including Android, iPhone, iPad, and iPod.

Features

  • Generates user agents for desktop (chrome, firefox, edge, safari, opera) and mobile (android, ios, iphone, ipad, ipod, samsung, mobile).
  • ios produces iPhone, iPad, or iPod user agents.
  • mobile produces a mix of Android, iPhone, iPad, or iPod user agents.
  • Random type selection with weighted probabilities (e.g., 25% Chrome, 20% Android).
  • MIT License, ready for open-source use.

Requirements

  • PHP 7.0 or higher (uses random_int).

Installation

  1. Clone or download the repository:
    git clone https://github.com/tuberboy/useragent-generator.git
  2. Include the class in your PHP project:
    require 'UserAgentGenerator.php';

Optional: Use Composer for autoloading:

composer require tuberboy/useragent-generator

Usage

Create an instance and generate user agents:

require 'UserAgentGenerator.php';
$generator = new UserAgentGenerator();

// Specific type
echo $generator->generate('chrome') . "\n"; // Chrome user agent
echo $generator->generate('ios') . "\n";    // iPhone, iPad, or iPod user agent
echo $generator->generate('mobile') . "\n"; // Android, iPhone, iPad, or iPod user agent

// Random type
echo $generator->generate() . "\n";         // Random user agent

// Original pattern
$randUA = ['mobile', 'iphone', 'ios'];
echo $generator->generate($randUA[array_rand($randUA)]) . "\n";

Example Output

Mozilla/5.0 (Windows NT 10.2; Win64; x64) AppleWebKit/612.45 Chrome/115.0.5790.234 Safari/612.2
Mozilla/5.0 (iPhone14; CPU iPhone OS 17_4_1) AppleWebKit/537.45 CriOS/16.2 Mobile/19B456 Safari/537.3
Mozilla/5.0 (Linux; Android 13; OnePlus 10 Pro) AppleWebKit/612.45 Version/17.2 Mobile/19B456 Safari/612.3
Mozilla/5.0 (Macintosh; Intel Mac OS X 12_4_2) Gecko/20130401 Firefox/122.7
Mozilla/5.0 (iPad; CPU OS 17_1_2) AppleWebKit/614.34 Version/17.1 Mobile/21C789 Safari/614.2

Supported Types

  • Desktop: chrome, firefox, edge, safari, opera
  • Mobile: android, ios, iphone, ipad, ipod, samsung, mobile
  • Notes:
    • ios: Only iPhone, iPad, or iPod.
    • mobile: Mix of Android, iPhone, iPad, or iPod.
    • Invalid types default to chrome.

License

This project is licensed under the MIT License.

Contributing

Feel free to submit issues or pull requests on GitHub.

About

A PHP library to generate over 5 trillion unique, realistic user agents for desktop and mobile devices. Supports browsers like Chrome, Firefox, and Safari, and devices including Android, iPhone, iPad, and iPod.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages