matomo-org /device-detector

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

★ 3,558⑂ 525👁 92⑃ 2,419● 838▤ 117
PHPLGPL-3.0Created 2014-04-02devicedetector.net
TA的项目
下载:6.5.26.5.2 ↓6.5.22026-09-29
3,558
stars
525
forks
92
watchers
2,419
prs
838
issues
117
releases

README

DeviceDetector
==============





 Code Status










 Description

The Universal Device Detection library that parses User Agents and Browser Client Hints to detect devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, feed readers, media players, PIMs, ...), operating systems, brands and models.

 Usage

Using DeviceDetector with composer is quite easy. Just add matomo/device-detector to your projects requirements.


composer require matomo/device-detector


And use some code like this one:


php
require_once 'vendor/autoload.php';

use DeviceDetector\ClientHints;
use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Device\AbstractDeviceParser;

// 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
AbstractDeviceParser::setVersionTruncation(AbstractDeviceParser::VERSION_TRUNCATION_NONE);

$userAgent = $_SERVER['HTTP_USER_AGENT']; // change this to the useragent you want to parse

// Client Hints are optional
// If you want to use them your server must announce that it supports client hints, using the Accept-CH header to specify the hints that it is interested in receiving.
// See e.g. https://developer.mozilla.org/en-US/docs/Web/HTTP/Client_hints
$clientHints = ClientHints::factory($_SERVER);

$dd = new DeviceDetector($userAgent, $clientHints);

// 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. Several cache bridges are supported:
// $dd-setCache(new DeviceDetector\Cache\DoctrineBridge(...));
// $dd-setCache(new DeviceDetector\Cache\LaravelCache(...));
// $dd-setCache(new DeviceDetector\Cache\PSR6Bridge(...));
// $dd-setCache(new DeviceDetector\Cache\PSR16Bridge(...));
// Instead of ... provide respective cache object, for example:
// $dd-setCache(new DeviceDetector\Cache\PSR6Bridge(new Symfony\Component\Cache\Adapter\ApcuAdapter('matomo')));

// 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
// $dd-setYamlParser(new DeviceDetector\Yaml\Symfony());
// $dd-setYamlParser(new DeviceDetector\Yaml\Pecl());

// 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 =

Top issues

Latest release

6.5.2 6.5.2 2026-09-29
What's Changed
 Improves detection for iPadOS by @liviuconcioiu in https://github.com/matomo-org/device-detector/pull/8284
 Improves detection for Avast Secure Browser by @liviuconcioiu in https://github.com/matomo-org/device-detector/pull/8291
 Adds detection for Amazon Prime Video and improves detection for Facebook by @liviuconcioiu in https://github.com/matomo-org/device-detector/pull/8297
 Adds detection for Android Go by @liviuconcioiu in https://github.com/matomo-org/device-detector/pull/8296
 Improves version detection for iOS, iPadOS, macOS and tvOS by @liviuconcioiu in https://g

Snapshot: 2026-11-17T21:58:29Z · Data license Apache-2.0 · JSON