poowaa/browser-detect-standalone

基于 hisorange/browser-detect 的独立 PHP 浏览器及移动设备检测包。

1.0.1 2019-06-06 17:42 UTC

This package is auto-updated.

Last update: 2024-09-07 05:37:07 UTC


README

这是一个易于使用的包,用于识别用户的浏览器详情和设备类型。不涉及魔法,结果由多个经过充分测试和开发的包生成。支持从 PHP 5.6 到 7.2 的每个版本。

如何安装

composer require PoOwAa/browser-detect-standalone

就是这样!

如何使用

如果您想使用用户的浏览器,则只需使用 Browser 类

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>';
}

如果您想处理自定义用户代理,则使用 Parser 类

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>';
}

可用的 API 调用

Browser 对象的每个调用都会反映到结果对象上,因此您可以在结果上使用以下信息,您可以使用数组语法来访问它们。