Giter Site home page Giter Site logo

browser-detect-standalone's Introduction

Standalone PHP Browser Detection based on hisorange/browser-detect

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)

browser-detect-standalone's People

Watchers

 avatar

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.