当前位置: 首页 > 软件库 > 开发工具 > PHP开发工具 >

browser-detect

Browser Detection for Laravel by hisorange!
授权协议 MIT License
开发语言 PHP
所属分类 开发工具、 PHP开发工具
软件类型 开源软件
地区 不详
投 递 者 赫连秦迟
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Browser Detection Logo

Browser Detection v4.4 by hisorange

Latest Stable VersionBuildCoverage StatusTotal DownloadsLicense

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 willcost 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 implementedevery user request which was feasable, and running out of ideas for the future. By this statementI am declaring this as the last feature release at version 4.2, from now on I will maintain compatibilitywith 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.

  • A useful but often overrated JavaScript function is the browser detect. Sometimes you want to give specific instructions or load a new page in case the viewer uses, for instance, Safari. If you're new

  • http://www.quirksmode.org/js/detect.html var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || ""; this.version = this.searchVersion(navigator.userAgent)

  • Mobile_Detect 是一个轻量级的开源移动设备(手机)检测的 PHP Class, 它使用 User-Agent 中的字符串,并结合 HTTP Header,来检测移动设备环境。 这个设备检测的 PHP 类库最强大的地方是,它有一个非常完整的库, 可以检测出所用的设备类型(包括操作类型,以及手机品牌等都能检测)和浏览器的详细信息。 官方主页:http://mobiledetect.net/

  • PHP script executed terminal PHP script can be possiblly terminaled in those situations: 1, Max time limiation is reaching. 2, The user hit "stop" button, and in backup server, ignore_user_abort is no

  • 首先推荐一个php轻量级识别类,Mobile-Detect 专门识别是手机端还是pc端访问网站,这样就可以根据访问的终端类型指向手机浏览器适配的网站还是pc浏览器的网站。 Mobile-Detect官网链接如下MobileDetect    示例链接如下:Mobile-Detect Example(本文后面有释义) [ js版下载地址:https://github.com/hgoebl/mobil

 相关资料
  • Object: Browser 包含浏览器各种属性的对象。 Browser.Features Browser.Features.xpath - (boolean) True如果浏览器支持XPath 。 Browser.Features.air - (boolean) True如果浏览器支持AIR 。 Browser.Features.query - (boolean) True如果浏览器支持que

  • Run Prettier in the browser with the standalone.js UMD bundle shipped in the NPM package (starting in version 1.13). The UMD bundle only formats the code and has no support for config files, ignore fi

  • extends: EventEmitter 当 Puppeteer 连接到一个 Chromium 实例的时候会通过 puppeteer.launch 或 puppeteer.connect 创建一个 Browser 对象。 下面是使用 Browser 创建 Page 的例子 const puppeteer = require('puppeteer'); puppeteer.launch().th

  • Browser Actions Contents Manifest UI的组成部分 图标 tooltip Badge Popup Tips 范例 API reference: chrome.browserAction Methods setBadgeBackgroundColor setBadgeText setIcon setPopup setTitle Events onClicked 用 b

  • The expression browser is available at /graph on the Prometheus server, allowing you to enter any expression and see its result either in a table or graphed over time. This is primarily useful for ad-

  • File Browser 提供指定目录下的文件管理界面,可用于上传、删除、预览、重命名和编辑你的文件。它允许创建多个用户,每个用户可以有自己的目录。它可以用作独立的应用程序或中间件。 特性: 轻松登录系统 通过时尚的界面管理你的文件 管理用户、添加权限、设置范围 编辑你的文件 执行自定义命令 自定义你的安装 安装: File Browser 是一个二进制文件,可以用作独立的可执行文件。尽管如此,有

  • Helium 是 MacOS 下的一款浮动的浏览器窗口,允许您在保持工作效率的同时观看媒体,浏览网页并执行更多操作。 即使在切换任务时,您的内容也永远不会落后于其他窗口。 Helium支持可自定义的半透明模式,允许您同时查看内容和工作,而不会在半透明时拦截鼠标点击。 您可以在浮动内容后单击,拖动,滚动。 效果如下图所示:

  • OSS Browser 是阿里云开发的图形化管理工具。它提供了类似于 Windows 资源管理器的功能。使用 OSS Browser,您可以轻松查看、上传、下载和管理项目。 本工具使用开源框架 Angular 1.x + Electron制作。 Electron 框架可以让你使用 JavaScript,HTML 和 CSS 构建跨平台的桌面应用程序。它是基于 node.js 和 Chromium