koff / device-detector
通用设备检测库,可解析用户代理并检测设备(桌面、平板、手机、电视、汽车、游戏机等),客户端(浏览器、媒体播放器、移动应用、新闻阅读器、库等),操作系统,设备,品牌和型号。
Requires
- php: >=5.3.9
- symfony/yaml: ^2.8|^3.4|^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.0|^2.8
- matthiasmullie/scrapbook: @stable
- psr/cache: ^1.0
- psr/simple-cache: ^1.0
- symfony/debug: ^2.8|^3.4|^4.0
- symfony/phpunit-bridge: ^2.8|^3.4|^4.0
Suggests
- doctrine/cache: Can directly be used for caching purpose
This package is auto-updated.
Last update: 2024-09-25 07:58:39 UTC
README
代码状态
描述
通用设备检测库,可解析用户代理并检测设备(桌面、平板、手机、电视、汽车、游戏机等),客户端(浏览器、新闻阅读器、媒体播放器、个人信息管理工具等),操作系统,品牌和型号。
用法
使用composer的DeviceDetector非常简单。只需将piwik/device-detector添加到项目需求中。然后使用如下代码:
require_once 'vendor/autoload.php'; use DeviceDetector\DeviceDetector; use DeviceDetector\Parser\Device\DeviceParserAbstract; // OPTIONAL: Set version truncation to none, so full versions will be returned // By default only minor versions will be returned (e.g. X.Y) // for other options see VERSION_TRUNCATION_* constants in DeviceParserAbstract class DeviceParserAbstract::setVersionTruncation(DeviceParserAbstract::VERSION_TRUNCATION_NONE); $userAgent = $_SERVER['HTTP_USER_AGENT']; // change this to the useragent you want to parse $dd = new DeviceDetector($userAgent); // OPTIONAL: Set caching method // By default static cache is used, which works best within one php process (memory array caching) // To cache across requests use caching in files or memcache // $dd->setCache(new Doctrine\Common\Cache\PhpFileCache('./tmp/')); // OPTIONAL: Set custom yaml parser // By default Spyc will be used for parsing yaml files. You can also use another yaml parser. // You may need to implement the Yaml Parser facade if you want to use another parser than Spyc or [Symfony](https://github.com/symfony/yaml) // $dd->setYamlParser(new DeviceDetector\Yaml\Symfony()); // OPTIONAL: If called, getBot() will only return true if a bot was detected (speeds up detection a bit) // $dd->discardBotInformation(); // OPTIONAL: If called, bot detection will completely be skipped (bots will be detected as regular devices then) // $dd->skipBotDetection(); $dd->parse(); if ($dd->isBot()) { // handle bots,spiders,crawlers,... $botInfo = $dd->getBot(); } else { $clientInfo = $dd->getClient(); // holds information about browser, feed reader, media player, ... $osInfo = $dd->getOs(); $device = $dd->getDeviceName(); $brand = $dd->getBrandName(); $model = $dd->getModel(); }
在某些情况下,可能只需要使用特定的解析器而不是DeviceDetector的全部功能。如果您只想检查给定的用户代理是否为机器人,而不需要其他信息,可以直接使用机器人解析器。
require_once 'vendor/autoload.php'; use DeviceDetector\Parser\Bot AS BotParser; $botParser = new BotParser(); $botParser->setUserAgent($userAgent); // OPTIONAL: discard bot information. parse() will then return true instead of information $botParser->discardDetails(); $result = $botParser->parse(); if (!is_null($result)) { // do not do anything if a bot is detected return; } // handle non-bot requests
不使用composer的使用方法
除了使用composer,您还可以使用包含的autoload.php
。此脚本将为DeviceDetector
命名空间中的所有类注册一个自动加载器。
需要YAML解析器。默认使用Spyc
解析器。由于此库未包含在内,您需要手动包含它或使用其他YAML解析器。
<?php include_once 'path/to/spyc/Spyc.php'; include_once 'path/to/device-detector/autoload.php'; use DeviceDetector\DeviceDetector; $deviceDetector = new DeviceDetector(); // ...
缓存
默认情况下,DeviceDetector使用内置的数组缓存。为了获得更好的性能,您可以使用自己的缓存解决方案。
- 您可以创建一个实现
DeviceDetector\Cache\Cache
的类。 - 您可以直接使用Doctrine缓存对象(如果您的项目已经使用Doctrine)。
- 如果您的项目使用符合PSR-6或PSR-16的缓存系统(如symfony/cache或matthiasmullie/scrapbook),您可以通过以下方式注入它们:
// Example with PSR-6 and Symfony $cache = new Symfony\Component\Cache\Adapter\ApcuAdapter(); $dd->setCache( new DeviceDetector\Cache\PSR6Bridge($cache) ); // Example with PSR-16 and ScrapBook $cache = new \MatthiasMullie\Scrapbook\Psr16\SimpleCache( new \MatthiasMullie\Scrapbook\Adapters\Apc() ); $dd->setCache( new DeviceDetector\Cache\PSR16Bridge($cache) ); // Example with Doctrine $dd->setCache( new Doctrine\Common\Cache\ApcuCache() );
贡献
修改库
这是一个受LGPL v3或更高版本许可证保护的免费/开源库。
欢迎您的pull请求和/或反馈!
列出日志中的所有用户代理
有时,可能需要生成您网站上最常用的用户代理列表,可以使用以下命令从访问日志中提取此列表:
zcat ~/path/to/access/logs* | awk -F'"' '{print $6}' | sort | uniq -c | sort -rn | head -n20000 > /home/matomo/top-user-agents.txt
贡献者
由Matomo团队、Stefan Giehl、Matthieu Aubry、Michał Gaździk、Tomasz Majczak、Grzegorz Kaszuba、Piotr Banaszczyk以及贡献者创建。
我们一起构建最好的设备检测库。
我们期待您的贡献和pull请求!
测试
另请参阅:[Matomo QA](http://matomo.org/qa/)
运行测试
cd /path/to/device-detector
curl -sS https://getcomposer.org/installer | php
php composer.phar install
phpunit
Device Detector的其他语言版本
该工具已经有几个其他语言的版本。
- .NET https://github.com/totpero/DeviceDetector.NET
- Ruby https://github.com/podigee/device_detector
- Node.JS https://github.com/sanchezzzhak/node-device-detector
- Python 3 https://github.com/thinkwelltwd/device_detector
Device Detector能够检测的内容
以下列表是自动生成并定期更新的。其中一些可能不完整。
最后更新:2018/08/07
检测到的操作系统列表
AIX、Android、AmigaOS、Apple TV、Arch Linux、BackTrack、Bada、BeOS、BlackBerry OS、BlackBerry Tablet OS、Brew、CentOS、Chrome OS、CyanogenMod、Debian、DragonFly、Fedora、Firefox OS、Fire OS、FreeBSD、Gentoo、Google TV、HP-UX、Haiku OS、IRIX、Inferno、KaiOS、Knoppix、Kubuntu、GNU/Linux、Lubuntu、VectorLinux、Mac、Maemo、Mandriva、MeeGo、MocorDroid、Mint、MildWild、MorphOS、NetBSD、MTK / Nucleus、Nintendo、Nintendo Mobile、OS/2、OSF1、OpenBSD、PlayStation Portable、PlayStation、Red Hat、RISC OS、Remix OS、RazoDroiD、Sabayon、SUSE、Sailfish OS、Slackware、Solaris、Syllable、Symbian、Symbian OS、Symbian OS Series 40、Symbian OS Series 60、Symbian^3、ThreadX、Tizen、Ubuntu、WebTV、Windows、Windows CE、Windows IoT、Windows Mobile、Windows Phone、Windows RT、Xbox、Xubuntu、YunOs、iOS、palmOS、webOS
检测到的浏览器列表
360手机浏览器、360浏览器、Avant浏览器、ABrowse、ANT Fresco、ANTGalio、Aloha浏览器、Amaya、Amigo、Android浏览器、Arora、Amiga Voyager、Amiga Aweb、Atomic Web浏览器、Avast安全浏览器、BlackBerry浏览器、百度浏览器、百度Spark、Beonex、Bunjalloo、B-Line、Brave、BriskBard、BrowseX、Camino、Coc Coc、Comodo Dragon、Coast、Charon、Chrome Frame、Chrome、Chrome移动版iOS、Conkeror、Chrome移动版、CoolNovo、CometBird、ChromePlus、Chromium、Cyberfox、Cheshire、Cunaguaro、dbrowser、Deepnet浏览器、Dolphin、Dorado、Dooble、Dillo、Epic、Elinks、Element浏览器、GNOME网络浏览器、Espial TV浏览器、Firebird、Fluid、Fennec、Firefox、Firefox Focus、Flock、Firefox移动版、Fireweb、Fireweb导航器、Galeon、Google Earth、HotJava、Iceape、IBrowse、iCab、iCab移动版、Iridium、IceDragon、Isivioo、Iceweasel、Internet Explorer、IE移动版、Iron、Jasmine、Jig浏览器、Kindle浏览器、K-meleon、Konqueror、Kapiko、Kylo、Kazehakase、猎豹、LG浏览器、Links、LuaKit、Lunascape、Lynx、MicroB、NCSA Mosaic、Mercury、移动版Safari、Midori、MIUI浏览器、移动版丝袜、Maxthon、诺基亚浏览器、诺基亚OSS浏览器、诺基亚Ovi浏览器、NetSurf、NetFront、NetFront Life、NetPositive、Netscape、NTENT浏览器、Obigo、Odyssey Web浏览器、Off By One、ONE浏览器、Opera Mini、Opera移动版、Opera、Opera Next、Oregano、Openwave移动版浏览器、OmniWeb、Otter浏览器、Palm Blazer、Pale Moon、OPPO浏览器、Palm Pre、Puffin、Palm WebPro、Palmscape、Phoenix、Polaris、Polarity、Microsoft Edge、QQ浏览器、Qutebrowser、QupZilla、Rekonq、RockMelt、三星浏览器、Sailfish浏览器、SEMC-Browser、搜狗浏览器、Safari、Shiira、Skyfire、Seraphic Sraf、Sleipnir、SeaMonkey、Snowshoe、Sunrise、SuperBird、Streamy、Swiftfox、Tizen浏览器、TweakStyle、UC浏览器、Vivaldi、Vision移动版浏览器、WebPositive、Waterfox、wOS浏览器、WeTab浏览器、Yandex浏览器、Xiino
检测到的浏览器引擎列表
WebKit、Blink、Trident、基于文本的、Dillo、iCab、Elektra、Presto、Gecko、KHTML、NetFront、Edge、NetSurf
检测到的库列表
aiohttp、curl、Faraday、Go-http-client、Google HTTP Java客户端、Guzzle (PHP HTTP客户端)、HTTP_Request2、Java、Mechanize、OkHttp、Perl、Python Requests、Python urllib、Wget、WWW-Mechanize
检测到的媒体播放器列表
Audacious、Banshee、Boxee、Clementine、Deezer、FlyCast、Foobar2000、Instacast、iTunes、Kodi、MediaMonkey、Miro、NexPlayer、Nightingale、QuickTime、Songbird、Stagefright、SubStream、VLC、Winamp、Windows媒体播放器、XBMC
检测到的移动应用列表
AndroidDownloadManager、AntennaPod、Apple News、BeyondPod、bPod、Castro、Castro 2、DoggCatcher、Facebook、Facebook Messenger、FeedR、Google Play Newsstand、Google Plus、iCatcher、Instacast、Line、Overcast、Pinterest、Player FM、Pocket Casts、Podcast & Radio Addict、Podcast Republic、Podcasts、Podcat、Podcatcher Deluxe、Podkicker、Sina Weibo、WeChat、WhatsApp、Yahoo! Japan、Yelp Mobile、YouTube和使用AFNetworking的移动应用
检测到的个人信息管理器列表
Airmail、Barca、DAVdroid、Lotus Notes、MailBar、Microsoft Outlook、Outlook Express、Postbox、The Bat!、Thunderbird
检测到的新闻阅读器列表
Akregator、Apple PubSub、BashPodder、Downcast、FeedDemon、Feeddler RSS Reader、gPodder、Instacast、JetBrains Omea Reader、Liferea、NetNewsWire、Newsbeuter、NewsBlur、NewsBlur 移动应用、PritTorrent、Pulp、ReadKit、Reeder、RSS Bandit、RSS Junkie、RSSOwl、Stringer
检测到的设备品牌列表
3Q、4Good、Acer、Ainol、Airness、Airties、Aiwa、Alcatel、Allview、Altech UEC、Amazon、Amoi、Apple、Archos、Arnova、ARRIS、Asus、Audiovox、Avvio、Axxion、Azumi Mobile、BangOlufsen、Barnes & Noble、BBK、Becker、Beetel、BenQ、BenQ-Siemens、BGH、Bird、Bitel、Blackview、Blaupunkt、Blu、Bmobile、Boway、bq、Bravis、Brondi、Bush、Capitel、Captiva、Carrefour、Casio、Cat、Celkon、长虹、Cherry Mobile、中国移动、CnM、Coby Kyros、Compal、Compaq、ConCorde、Condor、Coolpad、Cowon、CreNova、Cricket、Crius Mea、Crosscall、Cube、CUBOT、Cyrus、Danew、Datang、Dbtel、Dell、Denver、Desay、DEXP、Dialog、Dicam、Digma、DMM、DNS、DoCoMo、Doogee、Doov、Dopod、Doro、Dune HD、E-Boda、Easypix、EBEST、ECS、EKO、Elephone、Energy Sistem、Ericsson、Ericy、Essential、Eton、eTouch、Evertek、Evolveo、Explay、Ezio、Ezze、Fairphone、Fly、Foxconn、Freetel、富士通、Garmin-Asus、Gateway、Gemini、技嘉、Gigaset、金立、GOCLEVER、Goly、Google、Gradiente、Grundig、海尔、HannSpree、华硕、Hi-Level、海信、Homtom、Hosin、HP、HTC、华为、Humax、Hyrican、现代、i-Joy、i-mate、i-mobile、iBall、iBerry、IconBIT、Ikea、iKoMo、iNew、Infinix、Inkti、Innostream、INQ、Intek、Intex、Inverto、iOcean、iTel、JAY-Tech、金雅拓、K-Touch、Karbonn、Kazam、KDDI、Kiano、Kingsun、Kogan、Komu、康佳、Konka、Konrow、酷派、酷比、Koridy、KT-Tech、Kumai、京瓷、蓝沃、Lanix、Lava、LCT、乐视、Lenco、联想、Le Pan、Lexand、Lexibook、LG、Lingwin、Loewe、Logicom、LYF、M.T.T.、Majestic、Manta Multimedia、Mecer、Mediacom、MediaTek、Medion、MEEG、魅族、Memup、梅茨、MEU、MicroMax、Microsoft、Mio、三菱、MIXC、MLLED、Mobiistar、Mobistel、Modecom、Mofut、摩托罗拉、Mpman、MSI、MyPhone、NEC、Neffos、Netgear、Newgen、NextBook、NGM、尼康、任天堂、Noain、Noblex、诺基亚、Nomi、Nous、Nvidia、O2、Obi、Odys、Onda、OnePlus、OPPO、Opsson、Orange、Ouki、OUYA、Overmax、Oysters、Palm、Panasonic、Pantech、PEAQ、Pentagram、Philips、phoneOne、先锋、Ployer、Point of View、Polaroid、PolyPad、Pomp、Positivo、PPTV、Prestigio、ProScan、PULID、Qilive、QMobile、Qtek、Quechua、Ramos、RCA 平板电脑、Readboy、Rikomagic、RIM、Roku、Rover、Sagem、三星、三洋、世嘉、Selevision、Sencor、Sendo、Senseit、SFR、夏普、西门子、创维、Smart、Smartfren、Smartisan、软银、索尼、索尼爱立信、Spice、Star、STK、Stonex、Storex、Sumvision、SunVan、SuperSonic、Supra、Symphony、T-Mobile、TB Touch、TCL、TechniSat、TechnoTrend、Teclast、Tecno Mobile、Telefunken、Telenor、Telit、Tesco、特斯拉、teXet、ThL、Thomson、天宇、TiPhone、Tolino、Toplux、东芝、TrekStor、Trevi、突尼斯电信、Turbo-X、TVC、Ulefone、UMIDIGI、Unknown、Unnecto、Unowhy、UTStarcom、Vastking、Vernee、Vertu、Verykool、Vestel、Videocon、Videoweb、ViewSonic、Vitelcom、Vivo、Vizio、VK Mobile、Vodafone、Vonino、Voto、Voxtel、华硕、Web TV、WellcoM、Wexler、Wiko、Wileyfox、Wolder、Wolfgang、Wonu、Woxter、小米、Xolo、Yarvik、Ytone、源道、宇讯、Zen、Zonda、Zopo、中兴
检测到的机器人列表
360Spider、Aboundexbot、Acoon、AddThis.com、ADMantX、aHrefs Bot、Alexa Crawler、Alexa Site Audit、Amorank Spider、Analytics SEO Crawler、ApacheBench、Applebot、archive.org bot、Ask Jeeves、Backlink-Check.de、BacklinkCrawler、百度蜘蛛、BazQux Reader、BingBot、BitlyBot、Blekkobot、BLEXBot Crawler、Bloglovin、Blogtrottr、Bountii Bot、Browsershots、BUbiNG、Butterfly Robot、CareerBot、Castro 2、Catchpoint、ccBot crawler、Charlotte、Cliqzbot、CloudFlare Always Online、CloudFlare AMP Fetcher、Collectd、CommaFeed、CSS Certificate Spider、Cốc Cốc Bot、Datadog Agent、Dataprovider、Daum、Dazoobot、Discobot、Domain Re-Animator Bot、DotBot、DuckDuckGo Bot、Easou Spider、EMail Exractor、EmailWolf、evc-batch、ExaBot、ExactSeek Crawler、Ezooms、Facebook External Hit、Feedbin、FeedBurner、Feedly、Feedspot、Feed Wrangler、Fever、Findxbot、Flipboard、Generic Bot、Generic Bot、Genieo Web filter、Gigablast、Gigabot、Gluten Free Crawler、Gmail Image Proxy、Goo、Googlebot、Google PageSpeed Insights、Google Partner Monitoring、Google Structured Data Testing Tool、Grapeshot、Heritrix、Heureka Feed、HTTPMon、HubPages、HubSpot、ICC-Crawler、ichiro、IIS Site Analysis、Inktomi Slurp、IP-Guide Crawler、IPS Agent、Kouio、Larbin web crawler、Let's Encrypt Validation、Lighthouse、Linkdex Bot、LinkedIn Bot、LTX71、Lycos、Magpie-Crawler、MagpieRSS、Mail.Ru Bot、masscan、Meanpath Bot、MetaInspector、MetaJobBot、Mixrank Bot、MJ12 Bot、Mnogosearch、MojeekBot、Monitor.Us、Munin、Nagios check_http、NalezenCzBot、Netcraft Survey Bot、netEstate、NetLyzer FastProbe、NetResearchServer、Netvibes、NewsBlur、NewsGator、NLCrawler、Nmap、Nutch-based Bot、Octopus、Omgili bot、Openindex Spider、OpenLinkProfiler、OpenWebSpider、Orange Bot、Outbrain、PagePeeker、PaperLiBot、Phantomas、PHP Server Monitor、Picsearch bot、Pingdom Bot、Pinterest、PocketParser、Pompos、PritTorrent、QuerySeekerSpider、Quora Link Preview、Qwantify、Rainmeter、RamblerMail Image Proxy、Reddit Bot、Riddler、Rogerbot、ROI Hunter、SafeDNSBot、Scooter、ScoutJet、Scrapy、Screaming Frog SEO Spider、ScreenerBot、Semrush Bot、Sensika Bot、Sentry Bot、SEOENGBot、SEOkicks-Robot、Seoscanners.net、Server Density、Seznam Bot、Seznam Email Proxy、Seznam Zbozi.cz、ShopAlike、ShopWiki、SilverReader、SimplePie、SISTRIX Crawler、Site24x7 Website Monitoring、SiteSucker、Sixy.ch、Skype URI Preview、Slackbot、搜狗蜘蛛、360搜索蜘蛛、Sparkler、Speedy、Spinn3r、Sputnik Bot、sqlmap、SSL Labs、StatusCake、Superfeedr Bot、Survey Bot、Tarmot Gezgin、TelegramBot、TinEye Crawler、Tiny Tiny RSS、TLSProbe、Trendiction Bot、TurnitinBot、TweetedTimes Bot、Tweetmeme Bot、Twitterbot、UkrNet Mail Proxy、UniversalFeedParser、Uptimebot、Uptime Robot、URLAppendBot、Vagabondo、Visual Site Mapper Crawler、W3C CSS Validator、W3C I18N Checker、W3C Link Checker、W3C Markup Validation Service、W3C MobileOK Checker、W3C Unified Validator、Wappalyzer、WebbCrawler、WebSitePulse、WebThumbnail、WeSEE:Search、Willow Internet Crawler、WordPress、Wotbox、YaCy、Yahoo! Cache System、Yahoo! Link Preview、Yahoo! Slurp、Yahoo Gemini、Yandex Bot、Yeti/Naverbot、Yottaa Site Monitor、有道搜索机器人、Yourls、云云机器人、草料、Zao、zgrab、Zookabot、ZumBot