poowaa/browser-detect-standalone

Browser & Mobile detection package standalone PHP based on hisorange/browser-detect.

1.0.1 2019-06-06 17:42 UTC

This package is auto-updated.

Last update: 2024-04-07 04:35:54 UTC


README

Easy to use package to identify the user's browser details and device type. Magic is not involved the results are generated by multiple well tested and developed packages. Supporting every release PHP between 5.6 » 7.2.

How to install

composer require PoOwAa/browser-detect-standalone

Yep, that's it!

How to use

If you want to use the user's browser, then simply use the Browser class:

use PoOwAa\BrowserDetect\Browser as Browser;

// Determine the user's device type is simple as this:
Browser::isMobile();
Browser::isTablet();
Browser::isDesktop();

// Every wondered if it is a bot who loading your page?
if (Browser::isBot()) {
    echo 'No need to wonder anymore!';
}

// Check for vendors.
if (Browser::isFirefox() || Browser::isOpera()) {
    $output .= '<script src="firefox-fix.js"></script>';
}

If you want to handle custom useragent, then use the Parser class:

use PoOwAa\BrowserDetect\Parser;

$customBrowser = new PoOwAa\BrowserDetect\Parser('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36');

// Determine the user's device type is simple as this:
$customBrowser->isMobile();
$customBrowser->isTablet();
$customBrowser->isDesktop();

// Every wondered if it is a bot who loading your page?
if ($customBrowser->isBot()) {
    echo 'No need to wonder anymore!';
}

// Check for vendors.
if ($customBrowser->isFirefox() || $customBrowser->isOpera()) {
    $output .= '<script src="firefox-fix.js"></script>';
}

Available API calls

Every call on the Browser object is mirrored to the result object, so the following informations are available on your result too, where you can use the array syntax to access them.

Call Response Internal Type
Browser::userAgent() Current visitor's HTTP_USER_AGENT string. (string)
Browser::isMobile() Is this a mobile device. (boolean)
Browser::isTablet() Is this a tablet device. (boolean)
Browser::isDesktop() Is this a desktop computer. (boolean)
Browser::isBot() Is this a crawler / bot. (boolean)
Browser related functions
Browser::browserName() Browser's human friendly name like Firefox 3.6, Chrome 42. (string)
Browser::browserFamily() Browser's vendor like Chrome, Firefox, Opera. (string)
Browser::browserVersion() Browser's human friendly version string. (string)
Browser::browserVersionMajor() Browser's semantic major version. (integer)
Browser::browserVersionMinor() Browser's semantic minor version. (integer)
Browser::browserVersionPatch() Browser's semantic patch version. (integer)
Browser::browserEngine() Browser's engine like: Blink, WebKit, Gecko. (string)
Operating system related functions
Browser::platformName() Operating system's human friendly name like Windows XP, MacOS 10. (string)
Browser::platformFamily() Operating system's vendor like Linux, Windows, MacOS. (string)
Browser::platformVersion() Operating system's human friendly version like XP, Vista, 10. (integer)
Browser::platformVersionMajor() Operating system's semantic major version. (integer)
Browser::platformVersionMinor() Operating system's semantic minor version. (integer)
Browser::platformVersionPatch() Operating system's semantic patch version. (integer)
Device related functions
Browser::deviceFamily() Device's vendor like Samsung, Apple, Huawei. (string)
Browser::deviceModel() Device's brand name like iPad, iPhone, Nexus. (string)
Browser::mobileGrade() Device's mobile grade in scale of A,B,C for performance. (string)
Browser vendor related functions
Browser::isChrome() Is this a chrome browser. (boolean)
Browser::isFirefox() Is this a firefox browser. (boolean)
Browser::isOpera() Is this an opera browser. (boolean)
Browser::isSafari() Is this a safari browser. (boolean)
Browser::isIE() Checks if the browser is an some kind of Internet Explorer (or Trident) (boolean)
Browser::isIEVersion() Compares to a given IE version (boolean)
Browser::isEdge() Is this a microsoft edge browser. (boolean)