承接 campo/random-user-agent 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

campo/random-user-agent

最新稳定版本:1.3.0

Composer 安装命令:

composer require campo/random-user-agent

包简介

Generate real random user-agents.

README 文档

README

Latest Version on Packagist Software License

Generate real random user-agents. The user agent list is largely pulled from the Firefox extension random-agent-spoofer h/t dillbyrne/random-agent-spoofer. Additional entries were sourced from UserAgentString.com and WiiBrew to provide more options for consoles and common web crawlers

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

Install

Via Composer

$ composer require campo/random-user-agent

Usage

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

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 & 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

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

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 1.19M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 157
  • 点击次数: 0
  • 依赖项目数: 30
  • 推荐数: 0

GitHub 信息

  • Stars: 146
  • Watchers: 5
  • Forks: 24
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-05