Package Data | |
---|---|
Maintainer Username: | hisorange |
Maintainer Contact: | hello@hisorange.me (Varga Zsolt) |
Package Create Date: | 2013-12-06 |
Package Last Update: | 2024-11-12 |
Home Page: | https://browser-detect.com |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-14 15:16:46 |
Package Statistics | |
---|---|
Total Downloads: | 6,605,456 |
Monthly Downloads: | 208,642 |
Daily Downloads: | 8,517 |
Total Stars: | 1,090 |
Total Watchers: | 29 |
Total Forks: | 143 |
Total Open Issues: | 11 |
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 laravel version between 5.0 » 5.6, also tested on every release PHP between 5.6 » 7.2.
composer require hisorange/browser-detect
Yep, that's it! At least for lavarel 5.5 and above, for 5.4 and below please read the extended installation.
In your classes and controllers just call the Browser facade:
// 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>';
}
Even in your blade templates:
{{-- Directives are built in laravel 5.5 and above! --}}
@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 key is supported.
@browser('isBot')
<p>Bots are identified too :)</p>
@endbrowser
Every call on the Browser facade 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) |
The following matrix is being continuously tested by the great and awesome Travis CI!
| ----- | PHP 5.6 | PHP 7.0 | PHP 7.1 | PHP 7.2 | | :---: | :-----: | :-----: | :-----: | :-----: | | Laravel 5.0 | ✓ | - | - | - | | Laravel 5.1 | ✓ | - | - | - | | Laravel 5.2 | ✓ | - | - | - | | Laravel 5.3 | ✓ | - | - | - | | Laravel 5.4 | ✓ | ✓ | ✓ | ✓ | | Laravel 5.5 | - | ✓ | ✓ | ✓ | | Laravel 5.6 | - | - | ✓ | ✓ |
* Cannot auto test the laravel 5.4 on PHP 7.1 because of version incompatibility between the PHPUnit, Laravel and the package testing library, but the versions are tested manually.
Laravel 4.x releases are not actively developed but you can still use the browser detect 1.x for it; You can find those releases under the versions tab. Please read the readme from the release use choose, after version 2.x the package was redesigned from the sketch so nor the installation nor the usage is the same.
If you are using laravel 5.4 and below you have to add the service provider in your config/app.php like this:
'providers' => [
// Package Service Providers...
\hisorange\BrowserDetect\ServiceProvider::class,
]
and don't forget to add the facade in the same file like this:
'aliases' => [
'Browser' => \hisorange\BrowserDetect\Facade::class,
]
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');
See the detailed changes in the CHANGELOG file.