2017 © Pedro Peláez
 

library browser-detect

Browser & Mobile detection package for Laravel.

image

hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  • Tuesday, May 22, 2018
  • by hisorange
  • Repository
  • 19 Watchers
  • 358 Stars
  • 408,357 Installations
  • PHP
  • 6 Dependents
  • 1 Suggesters
  • 68 Forks
  • 3 Open issues
  • 23 Versions
  • 10 % Grown

The README.md

Browser Detection Logo, (*1)

Browser Detection v5.0 by hisorange

Latest Stable Version Build Coverage Status Total Downloads License, (*2)

Easy to use package to identify the visitor's browser details and device type. Magic is not involved the results are generated by multiple well tested and developed packages., (*3)

Supports every Laravel version between 4.0 » 10.x; Also tested on every PHP version between 5.6 » 8.2., (*4)

How to install


composer require hisorange/browser-detect

Yep, it's ready to be used by You! ^.^, (*5)

How to use


In Your code just call the Browser facade:, (*6)

use Browser;

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

if (Browser::isMobile()) {
  // Redirect to the mobile version of the site.
}

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

// Check for common vendors.
if (Browser::isFirefox() || Browser::isOpera()) {
    $response .= '';
}

// Sometimes You may want to serve different content based on the OS.
if (Browser::isAndroid()) {
    $response .= '<a>Install our Android App!</a>';
} elseif (Browser::isMac() && Browser::isMobile()) {
    $response .= '<a>Install our iOS App!</a>';
}

Even in Your blade templates:, (*7)

@mobile


This is the MOBILE template!, (*8)

@include('your-mobile-template') @endmobile @tablet

This is the TABLET template!, (*9)

<link rel="stylesheet" href="tablet.css" title="Reduce the page size, load what the user need"> @endtablet @desktop

This is the DESKTOP template!, (*10)

@enddesktop {-- Every result key is supported --} @browser('isBot')

Bots are identified too :), (*11)

@endbrowser

Easy peasy, ain't it?, (*12)

Version support


The following matrix has been continuously tested by the great and awesome GitHub Actions!, (*13)

----- Browser Detect 1.x Browser Detect 2.x Browser Detect 3.x Browser Detect 4.x Browser Detect 5.x
Laravel 4.x - - -
Laravel 5.x - - -
Laravel 6.x - - - -
Laravel 7.x - - - -
Laravel 8.x - - - 4.4+ -
Laravel 9.x - - - 4.4+
Laravel 10.x - - - -
Standalone - - - 4.2+

Since 2013 the package runs tests on every possible PHP / Laravel version matrix., (*14)

Standalone mode, without Laravel!


Based on community requests; Now You can use the library without Laravel. Just simply use the Parser class as a static object., (*15)

use hisorange\BrowserDetect\Parser as Browser;

if (Browser::isLinux()) {
    // Works as well!
}

Available API calls


Every call on the Browser facade is proxied to a result object, so the following information are available on Your result too, where You can use the [array] syntax to access them., (*16)

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::deviceType() Enumerated response for [Mobile, Tablet, Desktop, and Bot] (string)
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, Mac 10. (string)
Browser::platformFamily() Operating system's vendor like Linux, Windows, Mac. (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)
Operating system extended functions
Browser::isWindows() Is this a windows operating system. (boolean)
Browser::isLinux() Is this a linux based operating system. (boolean)
Browser::isMac() Is this an iOS or Mac based operating system. (boolean)
Browser::isAndroid() Is this an Android operating system. (boolean)
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 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)
Miscellaneous
Browser::isInApp() Check for browsers rendered inside applications like android webview. (boolean)

Configuration, personalization


If You are using Laravel then after installation run the following command:, (*17)

# Will copy a config file to ~/app/config/browser-detect.php
php artisan vendor:publish

For standalone mode to apply Your custom configuration:, (*18)

use hisorange\BrowserDetect\Parser;

$browser = new Parser(null, null, [
    'cache' => [
        'interval' => 86400 // This will override the default configuration.
    ]
]);

$result = $browser->detect();

Since the package aims to be easy to use, there is not much to configure. But You can customize the cache and security values., (*19)

Advanced Usage Information


The code is designed to be an easy to use style, so every call You make on the Browser facade will access the result object and get the data for You, but You can parse agents other than the current user's., (*20)

// When You call the detect function You will get a result object, from the current user's agent.
$result = Browser::detect();

// If You wanna get browser details from a user agent other than the current user call the parse function.
$result = Browser::parse('Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14');

Worthy notion! The parser only parsing each user agent string once and then caches it, it uses an in-memory runtime cache for multiple calls in a single page load; And it will use the application's cache to persist the result for a week or so, this should provide You with a sufficient caching mechanism so the detection will cost less than 0.02 millisecond, this was tested with an 80,000 fake visit., (*21)

Changelog


See the detailed changes in the CHANGELOG file., (*22)

The Versions

22/05 2018

dev-staging

dev-staging https://github.com/hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Varga Zsolt (hisorange)

laravel browser user agent mobile detect tablet user-agent greenball hisorange analyize

22/05 2018

dev-develop

dev-develop https://github.com/hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Varga Zsolt (hisorange)

laravel browser user agent mobile detect tablet user-agent greenball hisorange analyize

23/03 2018

dev-stable

dev-stable https://github.com/hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Varga Zsolt (hisorange)

laravel browser user agent mobile detect tablet user-agent hisorange analyize

23/03 2018

3.1.4

3.1.4.0 https://github.com/hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Varga Zsolt (hisorange)

laravel browser user agent mobile detect tablet user-agent hisorange analyize

09/02 2018

3.1.3

3.1.3.0 https://github.com/hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Varga Zsolt (hisorange)

laravel browser user agent mobile detect tablet user-agent hisorange analyize

07/02 2018

3.1.2

3.1.2.0 https://github.com/hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Varga Zsolt (hisorange)

laravel browser user agent mobile detect tablet user-agent hisorange analyize

29/12 2017

3.1.1

3.1.1.0 https://github.com/hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Varga Zsolt (hisorange)

laravel browser user agent mobile detect tablet user-agent hisorange analyize

29/12 2017

3.1.0

3.1.0.0 https://github.com/hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Varga Zsolt (hisorange)

laravel browser user agent mobile detect tablet user-agent hisorange analyize

17/12 2017

3.0.1

3.0.1.0 https://github.com/hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Varga Zsolt (hisorange)

laravel browser user agent mobile detect tablet user-agent hisorange analyize

16/12 2017

3.0.0

3.0.0.0 https://github.com/hisorange/browser-detect

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Varga Zsolt (hisorange)

laravel browser user agent mobile detect tablet user-agent hisorange analyize

17/11 2017

dev-master

9999999-dev

Browser & Mobile detection package for Laravel 4-5.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent greenball hisorange

28/06 2017

2.0.6

2.0.6.0

Browser & Mobile detection package for Laravel 4-5.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent greenball hisorange

22/04 2015

2.0.2

2.0.2.0

Browser & Mobile detection package for Laravel 4-5.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent greenball hisorange

10/02 2015

2.0.0

2.0.0.0

Browser & Mobile detection package for Laravel 4-5.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent greenball hisorange

01/05 2014

1.0.4

1.0.4.0

Browser & Mobile detection package for Laravel 4.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent greenball hisorange

01/05 2014

1.0.3

1.0.3.0

Browser & Mobile detection package for Laravel 4.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent greenball hisorange

01/05 2014

1.0.2

1.0.2.0

Browser & Mobile detection package for Laravel 4.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent greenball hisorange

30/04 2014

1.0.1

1.0.1.0

Browser & Mobile detection package for Laravel 4.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent greenball hisorange

21/03 2014

dev-merge

dev-merge

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent

12/03 2014

dev-develop-1

dev-develop-1

Browser & Mobile detection package for Laravel 4.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent greenball hisorange

08/12 2013

0.9.2

0.9.2.0

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent

08/12 2013

0.9.1

0.9.1.0

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)

laravel browser user agent mobile tablet user-agent

06/12 2013

v0.9.0

0.9.0.0

Browser & Mobile detection package for Laravel.

  Sources   Download

MIT

The Requires

 

by Varga Zsolt (hisorange)
by Avatar hisorange

laravel browser user agent mobile tablet user-agent