Coder Social home page Coder Social logo

hexydec / agentzero Goto Github PK

View Code? Open in Web Editor NEW
20.0 3.0 2.0 700 KB

A zero knowledge library for extracting information from User-Agent strings

Home Page: https://hexydec.com/apps/user-agent-parser/

License: MIT License

PHP 100.00%
php user-agent user-agent-parser useragent useragentparser

agentzero's Introduction

AgentZero: Fast User-Agent Detection

A library for extracting information from User-Agent strings very fast.

Licence: MIT Tests Status Code Coverage

Description

Doesn't match full UA strings or patterns, instead it extracts and categorises features from UA strings, so is faster, and can handle new UA strings or variations of common UA patterns.

Most User-Agent detection libraries rely on lists of regular expressions to match user agent string patterns and extract information. With lots of patterns you can do an ok job of getting this info, but it is not dynamic enough, which leads to minor variations or new UA strings not being captured, and they tend to be quite slow.

AgentZero is a simple string matching library that splits the user agent strings up into tokens to extract information from each part, leading to more complete information, more flexibility in capturing new user agent strings, and better performance.

You can try out AgentZero online at https://hexydec.com/apps/user-agent-parser/, or run the supplied index.php file after installation.

Usage

To use AgentZero:

$ua = $_SERVER['HTTP_USER_AGENT']; // or whatever UA you want e.g:
$ua = 'Mozilla/5.0 (Linux; Android 13; Pixel 7 Pro Build/TD1A.220804.031; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36 Instagram 301.1.0.33.110 Android (33/13; 420dpi; 1080x2116; Google/google; Pixel 7 Pro; cheetah; cheetah; en_GB; 517986703)';
$browser = \hexydec\agentzero\agentzero::parse($ua);

The returned value will be something like:

\hexydec\agentzero\agentzero (

	public readonly string 'string' => string 'Mozilla/5.0 (Linux; Android 13; Pixel 7 Pro Build/TD1A.220804.031; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36 Instagram 301.1.0.33.110 Android (33/13; 420dpi; 1080x2116; Google/google; Pixel 7 Pro; cheetah; cheetah; en_GB; 517986703)';

	// categories
	public readonly ?string 'type' => string 'human';
	public readonly ?string 'category' => string 'mobile';

	// device
	public readonly ?string 'vendor' => string 'Google';
	public readonly ?string 'device' => string 'Pixel';
	public readonly ?string 'model' => string '7 Pro';
	public readonly ?string 'build' => string 'TD1A.220804.031';
	public readonly ?int 'ram' => null;

	// architecture
	public readonly ?string 'processor' => null;
	public readonly ?string 'architecture' => null;
	public readonly ?int 'bits' => null;
	public readonly ?string 'cpu' => null;
	public readonly ?int 'cpuclock' => null;

	// platform
	public readonly ?string 'kernel' => string 'Linux';
	public readonly ?string 'platform' => string 'Android';
	public readonly ?string 'platformversion' => string '13';

	// browser
	public readonly ?string 'engine' => string 'Blink';
	public readonly ?string 'engineversion' => string '116.0.0.0';
	public readonly ?string 'browser' => string 'Chrome';
	public readonly ?string 'browserversion' => string '116.0.0.0';
	public readonly ?string 'language' => string 'en-GB';

	// app
	public readonly ?string 'app' => string 'Instagram';
	public readonly ?string 'appname' => string 'Instagram';
	public readonly ?string 'appversion' => string '301.1.0.33.110';
	public readonly ?string 'framework' => null;
	public readonly ?string 'frameworkversion' => null;
	public readonly ?string 'url' => null;

	// network
	public readonly ?string 'nettype' => null;
	public readonly ?string 'proxy' => null;

	// screen
	public readonly ?int 'width' => int 1080
	public readonly ?int 'height' => int 2116
	public readonly ?int 'dpi' => int 420
	public readonly ?float 'density' => null;
	public readonly ?bool 'darkmode' => null;;
);

You can read the full list of properties here.

Supported Features

AgentZero supports a wide range of architectures, browsers, rendering engines, platforms, devices, languages, and crawlers. Access the full list on the Supported Features page.

Installation

The easiest way to get up and running is to use composer:

$ composer require hexydec/agentzero

Test Suite

You can run the test suite like this:

Linux

$ vendor/bin/phpunit

Windows

> vendor\bin\phpunit

Support

AgentZero supports PHP version 8.1+.

Contributing

If you find an issue with AgentZero, please create an issue in the tracker.

If you wish to fix an issue yourself, please fork the code, fix the issue, then create a pull request, and I will evaluate your submission.

Licence

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

agentzero's People

Contributors

hexydec avatar thecrazybob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

agentzero's Issues

Wrong detection browser version of Safari browser.

Hello.

Wrong detection browser version of Safari browser.

For example,
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15

browserversion is should be 15.4, but detect 605.1.15.

Missing detection of Huawei Browser

Hello.

Android mobile Huawei Browser is not detected.

UserAgent examples:

Mozilla/5.0 (Linux; Android 12; GLA-LX1; HMSCore 6.12.0.302) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 HuaweiBrowser/14.0.0.322 Mobile Safari/537.36

Mozilla/5.0 (Linux; Android 10; EVE-LX9N; HMSCore 6.11.4.312) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 HuaweiBrowser/14.0.0.322 Mobile Safari/537.36

Mozilla/5.0 (Linux; Android 10; MED-LX9N; HMSCore 6.12.2.301) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 HuaweiBrowser/14.0.2.311 Mobile Safari/537.36

architecture: x86 + bits: 64

Hi - tnx for the good UA parser ;)

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.25 (KHTML, like Gecko)

Architecture | x86
Bits | 64

I think that can't be correct.

btw: no need to prefix standard PHP functions with a backslash "\", easier to read then (AFAIK except same custom function name).
maybe it is a liiiiittle bit faster with "\" (no need of the namespace resolution process).
and you have to use - for example - "use stdClass;" (after namespace).

Update on Release

@hexydec Hi!

Would you mind commenting back when this is out of BETA?

I found myself in search to replace an old User Agent repo, and was regoing through the tokeniser and its minifiers, and saw your new repo. So when it's ready you feel, I can give it some implementation and tests as well.

If that's cool with you? :)

Yandex browser detections

Hello.

Can you improve detection support of Yandex browsers?

YaApp_Android = Yandex Start
YaSearchBrowser = Yandex Alice
YaBrowser = Yandex

Thanky you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.