Browser Detection for Laravel by hisorange!

Overview

Browser Detection Logo

Browser Detection v4.4 by hisorange

Latest Stable Version Build Coverage Status Total Downloads License

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. Supporting every laravel version between 4.0 » 8.0, also tested on every PHP version between 5.6 » 8.0.

How to install


composer require hisorange/browser-detect

Yep, it's ready to be used by You! ^.^

How to use


In Your code just call the Browser facade:

use 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 common vendors.
if (Browser::isFirefox() || Browser::isOpera()) {
    $response .= '<script src="firefox-fix.js"></script>';
}

// Sometime 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:

@mobile
    <p>This is the MOBILE template!</p>
    @include('your-mobile-template')
@endmobile

@tablet
    <p>This is the TABLET template!</p>
    <link rel="stylesheet" href="tablet.css" title="Reduce the page size, load what the user need">
@endtablet

@desktop
    <p>This is the DESKTOP template!</p>
@enddesktop

{-- Every result key is supported --}
@browser('isBot')
    <p>Bots are identified too :)</p>
@endbrowser

Easy peasy, ain't it?

Version support


The following matrix is has been continuously tested by the great and awesome Github Actions!

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

Since 2013 the package runs tests on every possible PHP / Laravel version matrix.

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.

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.

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, 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::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)
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:

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

For standalone mode to apply Your custom configuration:

use hisorange\BrowserDetect\Parser;

$browser = new Parser(null, null, [
    'cache' => [
        'interval' => 86400 // This will overide 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.

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 then the current user's.

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

// If You wana get browser details from a user agent other then 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 inmemory 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 a 80,000 fake visit.

Community


At the time of this writing, the library is getting closer to be 7 year old. I have implemented every user request which was feasable, and running out of ideas for the future. By this statement I am declaring this as the last feature release at version 4.2, from now on I will maintain compatibility with new Laravel and PHP versions, but not planning to do any new features.

Thank You for your support over the years, and worry not, the library is stable, and has all the features You ever need.

~ Update on this :D

No major features are added in the past months, but with the help of Raymund Ács we are patching and continuing the support for micro features and version ports.

Changelog


See the detailed changes in the CHANGELOG file.

Comments
  • Only see

    Only see "HiSoRange Generic Browser" - Laravel 5.3

    Hi

    I've tried to make this work for a few hours now with no success...

    Followed your instructions. hisorange\BrowserDetect\Provider\BrowserDetectService::class, and 'BrowserDetect' => hisorange\BrowserDetect\Facade\Parser::class,

    in app.php

    but

     $result = \BrowserDetect::detect();
            dd($result);
    

    shows me only

    Result {#164 ▼
      #attributes: array:17 [▼
        "isMobile" => false
        "isTablet" => false
        "isDesktop" => true
        "isBot" => false
        "browserFamily" => "HiSoRange Generic Browser"
        "browserVersionMajor" => 0
        "browserVersionMinor" => 0
        "browserVersionPatch" => 0
        "osFamily" => "HiSoRange Generic OS"
        "osVersionMajor" => 0
        "osVersionMinor" => 0
        "osVersionPatch" => 0
        "deviceFamily" => ""
        "deviceModel" => ""
        "mobileGrade" => ""
        "cssVersion" => 0
        "javaScriptSupport" => true
      ]
    }
    

    I tried it with Google Chrome and Firefox (both latest Windows versions), same result.

    Is there anything I'm missing?

    Using Laravel 5.3

    thanks!

    opened by steve-rhodes 15
  • Browser version is not shown

    Browser version is not shown

    Hello,

    I'm using Laravel 5.1.27

    When I do this:

    var_dump(\BrowserDetect::browserVersion());
    

    I get a empty string.

    Even if I do this:

    $browser = \BrowserDetect::detect()->toArray();
    dd($browser);
    

    The versions (major, minor, patch) of browser and os, it is always zero.

    I tried this with Chrome, Firefox and Safari on a MacBook.

    Or maybe this is normal when I see an application locally?

    Thanks.

    opened by rcaf 13
  • Calling \Browser::isMobile() throws the error:

    Calling \Browser::isMobile() throws the error: "Argument 1 passed to UAParser\Parser::parse() must be of the type string, null given"

    Hello after I updated this package I'm getting this error:

    Argument 1 passed to UAParser\Parser::parse() must be of the type string, null given, called in /sites/152577226/vendor/hisorange/browser-detect/src/Stages/UAParser.php on line 25
    

    The code causing this is simply:

    if (\Browser::isMobile()) {

    It seems like in the update you tried to add some stronger typing, but there was some error.

    The package update that resulted in this error was updating from 3.12.4 to 3.12.5

    Bug Stale 
    opened by paulcdejean 9
  • Yaml::parse() error when using BrowserDetect class

    Yaml::parse() error when using BrowserDetect class

    I updated composer yesterday and wherever I use this class, I get an error as follows:

    ErrorException (E_UNKNOWN) The ability to pass file names to Yaml::parse() was deprecated in 2.2 and will be removed in 3.0. Please, pass the contents of the file instead.

    Here is a sample code of what fails:

    I am using browser-detect on a Laravel 4.x installation. As soon as I remove this, my page works fine.

    opened by djtechonline 9
  • browscap ini pulling

    browscap ini pulling

    Tested with and without the plugin, cleared cache and tested in multiple browsers.

    ErrorException file_get_contents(http://browscap.org/stream?q=Full_PHP_BrowsCapINI): failed to open stream: HTTP request failed! HTTP/1.1 429 Too Many Requests (View: /*_/_/app/views/home/index.blade.php)

    opened by goranata 9
  • Not Working on L 5.2

    Not Working on L 5.2

    I've used this command : $result = \BrowserDetect::isMobile(); but it returns : Class 'BrowserDetect' not found

    Here is my app.php : providers' => [ hisorange\BrowserDetect\Provider\BrowserDetectService::class, ]

    And Alias is : aliases' => [ 'BrowserDetect' => hisorange\BrowserDetect\Facade\Parser::class, ]

    Any ideas?

    opened by kamrava 8
  • iPad is being detected as mobile instead of tablet

    iPad is being detected as mobile instead of tablet

    Hi mate, first of all thanks for you work, it's awesome! I'm using it in production in a site called Resermap (www.resermap.com) and it's detecting that the iPad is a mobile (redirecting it to the mobile web site) instead of keeping it in the regular (responsive) website, as a tablet should do. Do I have to configure something else for this to work as I mention? Thanks again!

    opened by ivancevich 8
  • Browser::parse(): failed to open stream: Permission denied

    Browser::parse(): failed to open stream: Permission denied

    When doing Browser::parse($agent)

    I sometimes get:

    file_put_contents(/var/www/html/hidden/storage/framework/cache/data/d8/ab/d8ab137e137fbf415d960746d1d2e63d409f2e20): failed to open stream: Permission denied

    Rarely, but it happened today. I know this would appear to be a permissions issue, but note the file exists and is world readable:

    $ ls /var/www/html/hidden/storage/framework/cache/data/d8/ab/d8ab137e137fbf415d960746d1d2e63d409f2e20
    
    -rw-r--r-- 1 www-data www-data 1.1K Feb  1 12:33 /var/www/html/hidden/storage/framework/cache/data/d8/ab/d8ab137e137fbf415d960746d1d2e63d409f2e20
    

    Any ideas? Using 4.2.2

    opened by futzlarson 7
  • Updates for laravel 6

    Updates for laravel 6

    Hello,

    @hisorange hope this helps you a bit. Just changed everthing to make this work. The change in ParserTest was because of an Warning from PhpUnit

    opened by SudoGetBeer 7
  • Browser version ending up being 0

    Browser version ending up being 0

    I get the following result using Chrome:

    isMobile: false,
    isTablet: false,
    isDesktop: true,
    isBot: false,
    browserFamily: "Chrome",
    browserVersionMajor: 0,
    browserVersionMinor: 0,
    browserVersionPatch: 0,
    osFamily: "MacOSX",
    osVersionMajor: 0,
    osVersionMinor: 0,
    osVersionPatch: 0,
    deviceFamily: "",
    deviceModel: "",
    mobileGrade: "",
    cssVersion: 1,
    javaScriptSupport: true
    

    and in Safari

    isMobile: false,
    isTablet :false,
    isDesktop:true,
    isBot: false,
    browserFamily: Safari,
    browserVersionMajor: 0,
    browserVersionMinor: 0,
    browserVersionPatch: 0,
    osFamily: MacOSX,
    osVersionMajor: 0,
    osVersionMinor: 0,
    osVersionPatch: 0,
    deviceFamily: "",
    deviceModel: "",
    mobileGrade: "",
    cssVersion: 1,
    javaScriptSupport: true
    

    Can this bug be fixed somehow or am I the only one getting it?

    opened by marktopper 7
  • Detecting Brave Browser

    Detecting Brave Browser

    Hi, is there a way to detect user that using Brave browser?

    Because I'm using it, and when testing with isChrome(), the result return true

    Thanks in advance

    Enhancement Stale 
    opened by xGwein 6
  • Browser::isMac() does not seem to work on some UA with iPad/iPod/iPhone in it

    Browser::isMac() does not seem to work on some UA with iPad/iPod/iPhone in it

    I have some UA that were iPhone's or iPad's but that were reported false with ìsMac`.

    Eg:

    • Mozilla/5.0 (iPad; CPU OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Mobile/15E148 Safari/604.1
    • Mozilla/5.0 (iPad; CPU OS 14_8_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1

    Both of these aren't working while despite the following working and having the same signature :

    • Mozilla/5.0 (iPad; CPU OS 9_3_5 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13G36 Safari/601.1

    Any idea what's going wrong?

    opened by darkylmnx 0
Releases(4.5.4)
Owner
Varga Zsolt
WebArtisan since ~2003
Varga Zsolt
Laravel ClickHouse adds CH client integration, generation & execution of ClickHouse database migrations to the Laravel application.

Laravel ClickHouse Introduction Laravel ClickHouse database integration. This package includes generation and execution of the ClickHouse database mig

cybercog 11 Dec 20, 2022
A Laravel package to retrieve pageviews and other data from Google Analytics

Retrieve data from Google Analytics Using this package you can easily retrieve data from Google Analytics. Here are a few examples of the provided met

Spatie 2.8k Jan 7, 2023
A DigitalOcean API bridge for Laravel

Laravel DigitalOcean Laravel DigitalOcean was created by, and is maintained by Graham Campbell, and is a DigitalOcean PHP API Client bridge for Larave

Graham Campbell 421 Dec 20, 2022
A GitHub API bridge for Laravel

Laravel GitHub Laravel GitHub was created by, and is maintained by Graham Campbell, and is a PHP GitHub API bridge for Laravel. It utilises my Laravel

Graham Campbell 547 Dec 30, 2022
Manage newsletters in Laravel

Manage newsletters in Laravel This package provides an easy way to integrate MailChimp with Laravel. Should you find that Mailchimp is too expensive f

Spatie 1.5k Jan 2, 2023
[DEPRECATED] A Pusher Channels bridge for Laravel

DEPRECATED Laravel now has built-in support for Pusher Channels. This is now the recommended approach to integrate Channels into a Laravel project. Cu

Pusher 406 Dec 28, 2022
A simple API documentation package for Laravel using OpenAPI and Redoc

Laravel Redoc Easily publish your API documentation using your OpenAPI document in your Laravel Application. Installation You can install this package

Steve McDougall 15 Dec 27, 2022
TeleBot - Easy way to create Telegram-bots in PHP. Rich Laravel support out of the box.

TeleBot is a PHP library for telegram bots development. Rich Laravel support out of the box. Has an easy, clean, and extendable way to handle telegram Updates.

WeStacks 206 Jan 6, 2023
laravel wrapper for dicom images services

laravel wrapper for dicom images services

Laravel Iran Community 4 Jan 18, 2022
A Laravel package to help integrate Shopware PHP SDK much more easier

Shopware 6 Laravel SDK A Laravel package to help integrate Shopware PHP SDK much more easier Installation Install with Composer composer require sas/s

Shape & Shift 16 Nov 3, 2022
laravel package untuk memudahkan penggunaan MCA dengan Telegram Bot USDI di aplikasi Universitas Udayana.

MCA KubeMQ Laravel laravel package untuk memudahkan penggunaan MCA dengan Telegram Bot USDI di aplikasi Universitas Udayana. Motivasi Proyek ini berfu

Ristek USDI 1 Nov 17, 2021
Integrate RajaOngkir API with laravel

Baca ini dalam bahasa: Indonesia This is my package laravel-rajaongkir Installation You can install the package via composer: composer require kodepin

Kode Pintar 6 Aug 11, 2022
A Laravel SQS driver that removes the 256KB payload limit by saving the payloads into S3.

Simple SQS Extended Client Introduction Simple SQS Extended Client is a Laravel queue driver that was designed to work around the AWS SQS 256KB payloa

Simple Software LLC 7 Dec 8, 2022
Google VerifiedSMS Laravel Package

Google VerifiedSMS Laravel Package This is a laravel package developed for google business communication api and verified SMS API. Before we commence

Saju G 2 Nov 22, 2021
A Laravel wrapper for thephpleague's Fractal package

laravel-api-response A Laravel wrapper for thephpleague's Fractal package Install Via Composer composer require lykegenes/laravel-api-response Then, a

Patrick Samson 3 Mar 15, 2021
A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax

Fluent-Facebook Docs A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax. Check out how easy it is to

iluminar 47 Dec 8, 2022
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.

Telegram Bot API - PHP SDK Telegram Bot PHP SDK lets you develop Telegram Bots in PHP easily! Supports Laravel out of the box. Telegram Bot API is an

Irfaq Syed 2.5k Jan 6, 2023
Facebook GraphQL for Laravel 5. It supports Relay, eloquent models, validation and GraphiQL.

Laravel GraphQL This package is no longuer maintained. Please use rebing/graphql-laravel or other Laravel GraphQL packages Use Facebook GraphQL with L

Folklore Inc. 1.8k Dec 11, 2022
This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

Daniel Henze 3 Aug 29, 2022