承接 donatj/phpuseragentparser 相关项目开发

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

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

donatj/phpuseragentparser

Composer 安装命令:

composer require donatj/phpuseragentparser

包简介

Lightning fast, minimalist PHP UserAgent string parser.

README 文档

README

Join the chat at https://gitter.im/PhpUserAgentParser/Lobby

Latest Stable Version Total Downloads License ci.yml

What It Is

A simple, streamlined PHP user-agent parser!

Licensed under the MIT license: https://www.opensource.org/licenses/mit-license.php

Upgrading to 1.*

The new 1.* release does not break compatibility with 0.* and nothing need to change to upgrade. However, the global parse_user_agent is now deprecated; it has been replaced with the namespaced \donatj\UserAgent\parse_user_agent and functions exactly the same. You can easily replace any existing call to parse_user_agent with \donatj\UserAgent\parse_user_agent

In addition, 1.x adds a convenience object wrapper you may use should you prefer. More information on this is in the Usage section below.

Why Use This

You have your choice in user-agent parsers. This one detects all modern browsers in a very light, quick, understandable fashion. It is less than 200 lines of code, and consists of just three regular expressions! It can also correctly identify exotic versions of IE others fail on.

It offers 100% unit test coverage, is installable via Composer, and is very easy to use.

What It Does Not Do

This is not meant as a browser "knowledge engine" but rather a simple parser. Anything not adequately provided directly by the user agent string itself will simply not be provided by this.

OS Versions

User-agent strings are not a reliable source of OS Version!

  • Many agents simply don't send the information.
  • Others provide varying levels of accuracy.
  • Parsing Windows versions alone almost nearly doubles the size of the code.

I'm much more interested in keeping this thing tiny and accurate than adding niché features and would rather focus on things that can be done well.

All that said, there is the start of a branch to do it I created for a client if you want to poke it, I update it from time to time, but frankly if you need to reliably detect OS Version, using user-agent isn't the way to do it. I'd go with JavaScript.

Undetectable Browsers

  • Brave - Brave is simply not differentiable from Chrome. This was a design decision on their part.

Undetectable Platforms

  • iPadOS 13+ - Starting with iPadOS 13 and further hardened in 14, iPadOS returns the exact same string as macOS. It is no longer distinguishable by UA string. (See: #69)

Requirements

  • php: >=5.4.0
  • ext-ctype: *

Installing

PHP User Agent is available through Packagist via Composer.

Install the latest version with:

composer require 'donatj/phpuseragentparser'

Usage

The classic procedural use is as simple as:

<?php

// if you're using composer
require __DIR__ . '/../vendor/autoload.php';

// v0 style global function - @deprecated
$uaInfo = parse_user_agent();
// or
// modern namespaced function
$uaInfo = donatj\UserAgent\parse_user_agent();

echo $uaInfo[donatj\UserAgent\PLATFORM] . PHP_EOL;
echo $uaInfo[donatj\UserAgent\BROWSER] . PHP_EOL;
echo $uaInfo[donatj\UserAgent\BROWSER_VERSION] . PHP_EOL;

The new object-oriented wrapper form:

<?php

use donatj\UserAgent\UserAgentParser;

// if you're using composer
require __DIR__ . '/../vendor/autoload.php';

$parser = new UserAgentParser();

// object-oriented call
$ua = $parser->parse();
// or
// command style invocation
$ua = $parser();

echo $ua->platform() . PHP_EOL;
echo $ua->browser() . PHP_EOL;
echo $ua->browserVersion() . PHP_EOL;

Currently Tested Platforms

Predefined helper constants from donatj\UserAgent\Platforms

Constant Platform
Platforms::MACINTOSH Macintosh
Platforms::CHROME_OS Chrome OS
Platforms::LINUX Linux
Platforms::WINDOWS Windows
Platforms::ANDROID Android
Platforms::BLACKBERRY BlackBerry
Platforms::FREEBSD FreeBSD
Platforms::FUCHSIA Fuchsia
Platforms::IPAD iPad
Platforms::IPHONE iPhone
Platforms::IPOD iPod
Platforms::KINDLE Kindle
Platforms::KINDLE_FIRE Kindle Fire
Platforms::NETBSD NetBSD
Platforms::NEW_NINTENDO_3DS New Nintendo 3DS
Platforms::NINTENDO_3DS Nintendo 3DS
Platforms::NINTENDO_DS Nintendo DS
Platforms::NINTENDO_SWITCH Nintendo Switch
Platforms::NINTENDO_WII Nintendo Wii
Platforms::NINTENDO_WIIU Nintendo WiiU
Platforms::OPENBSD OpenBSD
Platforms::PLAYBOOK PlayBook
Platforms::PLAYSTATION_3 PlayStation 3
Platforms::PLAYSTATION_4 PlayStation 4
Platforms::PLAYSTATION_5 PlayStation 5
Platforms::PLAYSTATION_VITA PlayStation Vita
Platforms::SAILFISH Sailfish
Platforms::SYMBIAN Symbian
Platforms::TIZEN Tizen
Platforms::WINDOWS_PHONE Windows Phone
Platforms::XBOX Xbox
Platforms::XBOX_ONE Xbox One

Currently Tested Browsers

Note

There is overlap between browsers and bots. Before bots were given their own separate class, a number were added to the browser list. They appear in both lists for backward compatibility. This is likely to be remedied should there be a future major release.

Predefined helper constants from donatj\UserAgent\Browsers

Constant Browser
Browsers::ADSBOT_GOOGLE AdsBot-Google
Browsers::ANDROID_BROWSER Android Browser
Browsers::APPLEBOT Applebot
Browsers::BAIDUSPIDER Baiduspider
Browsers::BINGBOT bingbot
Browsers::BLACKBERRY_BROWSER BlackBerry Browser
Browsers::BROWSER Browser
Browsers::BUNJALLOO Bunjalloo
Browsers::CAMINO Camino
Browsers::CHATGPT_USER ChatGPT-User
Browsers::CHROME Chrome
Browsers::CURL curl
Browsers::EDGE Edge
Browsers::FACEBOOKEXTERNALHIT facebookexternalhit
Browsers::FEEDVALIDATOR FeedValidator
Browsers::FIREFOX Firefox
Browsers::GOOGLEBOT Googlebot
Browsers::GOOGLEBOT_IMAGE Googlebot-Image
Browsers::GOOGLEBOT_VIDEO Googlebot-Video
Browsers::GPTBOT GPTBot
Browsers::HEADLESSCHROME HeadlessChrome
Browsers::IEMOBILE IEMobile
Browsers::IMESSAGEBOT iMessageBot
Browsers::KINDLE Kindle
Browsers::LYNX Lynx
Browsers::MASTODON Mastodon
Browsers::MIDORI Midori
Browsers::MIUIBROWSER MiuiBrowser
Browsers::MSIE MSIE
Browsers::MSNBOT_MEDIA msnbot-media
Browsers::NETFRONT NetFront
Browsers::NINTENDOBROWSER NintendoBrowser
Browsers::OAI_SEARCHBOT OAI-SearchBot
Browsers::OCULUSBROWSER OculusBrowser
Browsers::OPERA Opera
Browsers::PUFFIN Puffin
Browsers::SAFARI Safari
Browsers::SAILFISHBROWSER SailfishBrowser
Browsers::SAMSUNGBROWSER SamsungBrowser
Browsers::SILK Silk
Browsers::SLACKBOT Slackbot
Browsers::TELEGRAMBOT TelegramBot
Browsers::TIZENBROWSER TizenBrowser
Browsers::TWITTERBOT Twitterbot
Browsers::UC_BROWSER UC Browser
Browsers::VALVE_STEAM_TENFOOT Valve Steam Tenfoot
Browsers::VIVALDI Vivaldi
Browsers::WGET Wget
Browsers::WHALE Whale
Browsers::WORDPRESS WordPress
Browsers::YANDEX Yandex
Browsers::YANDEXBOT YandexBot
Browsers::YETI Yeti

Tested Bots

Predefined helper constants from donatj\UserAgent\Bots

Constant Bots
Bots::ADKERNELTOPICCRAWLER AdkernelTopicCrawler
Bots::ADSBOT_GOOGLE AdsBot-Google
Bots::AHREFSBOT AhrefsBot
Bots::AHREFSSITEAUDIT AhrefsSiteAudit
Bots::AMAZONADBOT AmazonAdBot
Bots::AMAZONBOT Amazonbot
Bots::APPLEBOT Applebot
Bots::ARCHIVE_ORG_BOT archive.org_bot
Bots::AWARIOBOT AwarioBot
Bots::BAIDUSPIDER Baiduspider
Bots::BAIDUSPIDER_RENDER Baiduspider-render
Bots::BARKROWLER Barkrowler
Bots::BINGBOT bingbot
Bots::BLEXBOT BLEXBot
Bots::BRAVEBOT Bravebot
Bots::CENSYSINSPECT CensysInspect
Bots::CHATGPT_USER ChatGPT-User
Bots::CLAUDEBOT ClaudeBot
Bots::COCCOCBOT_IMAGE coccocbot-image
Bots::COCCOCBOT_WEB coccocbot-web
Bots::CURL curl
Bots::DATAFORSEOBOT DataForSeoBot
Bots::DISCORDBOT Discordbot
Bots::DOTBOT DotBot
Bots::DVBOT DVbot
Bots::EV_CRAWLER ev-crawler
Bots::FACEBOOKEXTERNALHIT facebookexternalhit
Bots::FEEDBOT feedbot
Bots::FEEDVALIDATOR FeedValidator
Bots::GOOGLEBOT Googlebot
Bots::GOOGLEBOT_IMAGE Googlebot-Image
Bots::GOOGLEBOT_VIDEO Googlebot-Video
Bots::GOOGLE_READ_ALOUD Google-Read-Aloud
Bots::GOOGLE_SAFETY Google-Safety
Bots::GPTBOT GPTBot
Bots::HEEXYBOT Heexybot
Bots::HUBSPOT_DOMAIN_CHECK HubSpot Domain check
Bots::IBOUBOT IbouBot
Bots::IMESSAGEBOT iMessageBot
Bots::LEIKIBOT Leikibot
Bots::MASTODON Mastodon
Bots::MINIFLUX Miniflux
Bots::MODATSCANNER ModatScanner
Bots::MOJEEKBOT MojeekBot
Bots::MSNBOT_MEDIA msnbot-media
Bots::OAI_SEARCHBOT OAI-SearchBot
Bots::PERPLEXITYBOT PerplexityBot
Bots::PERPLEXITY_USER Perplexity-User
Bots::PETALBOT PetalBot
Bots::PINTERESTBOT Pinterestbot
Bots::PROXIMIC proximic
Bots::SCOURRSSBOT ScourRSSBot
Bots::SEMRUSHBOT SemrushBot
Bots::SEMRUSHBOT_SI SemrushBot-SI
Bots::SERANKINGBACKLINKSBOT SERankingBacklinksBot
Bots::SEZNAMBOT SeznamBot
Bots::SLACKBOT Slackbot
Bots::SMTBOT SMTBot
Bots::SPIDERLING SpiderLing
Bots::SURDOTLYBOT SurdotlyBot
Bots::TELEGRAMBOT TelegramBot
Bots::TWITTERBOT Twitterbot
Bots::WELLKNOWNBOT WellKnownBot
Bots::WGET Wget
Bots::WORDPRESS WordPress
Bots::WPBOT wpbot
Bots::YANDEXBOT YandexBot
Bots::YANDEXIMAGES YandexImages
Bots::YANDEXMOBILEBOT YandexMobileBot
Bots::YANDEXRCA YandexRCA
Bots::YANDEXUSERPROXY YandexUserproxy
Bots::YETI Yeti

More information is available at Donat Studios.

donatj/phpuseragentparser 适用场景与选型建议

donatj/phpuseragentparser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.62M 次下载、GitHub Stars 达 595, 最近一次更新时间为 2013 年 05 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「parser」 「browser」 「user agent」 「useragent」 「browser detection」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 donatj/phpuseragentparser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 donatj/phpuseragentparser 我们能提供哪些服务?
定制开发 / 二次开发

基于 donatj/phpuseragentparser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17.62M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 604
  • 点击次数: 22
  • 依赖项目数: 62
  • 推荐数: 4

GitHub 信息

  • Stars: 595
  • Watchers: 30
  • Forks: 127
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-05-20