Download the PHP package foroco/php-browser-detection without Composer

On this page you can find all versions of the php package foroco/php-browser-detection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-browser-detection

PHP Browser Detection

A PHP library to detect browser, OS, platform and device type by User-Agent parsing.\ This library focused on high performance and low memory usage HTTP client parsing.\ Uses a simple and fast algorithm to accurately detect more than 200 browsers/apps and over 60 OS.\ For most commonly browsers parsing process took less than 0.0005 second even on low-level shared hosting.\ In the case of rare User-Agents recognized time is less than 0.0008 second for the same conditioned hosting environment.\ The library supports only really actual Browsers and OS without support for outdated environments that are actually not used now.\ Newest MacOS Monterey, MacOS Ventura and Windows 11 User-Agents detection included.\ Works by use only one library file and without any third-party libraries dependency.

Requirements

This library requires PHP 5.3 or higher.

Manual installation

  1. Simply upload library file BrowserDetection.php (placed in the src directory) to your project;
  2. Connect PHP library file by using require_once:

Installation by using Composer

Install this library using Composer:

composer require foroco/php-browser-detection

Update library package by running a command:

composer update foroco/php-browser-detection

The first step requires the Composer autoloader:

Usage

The library will try to get environment data from the HTTP_USER_AGENT header sent by the HTTP client. Library PHP Class BrowserDetection contains four public methods which return Array or JSON string of recognized data from HTTP_USER_AGENT:

First argument should contain User-Agent string from the HTTP_USER_AGENT header or your custom User-Agent string.\ Second argument (optional) may contain 'JSON' if you want to get returned result as JSON format.

The library class BrowserDetection also contains special method setTouchSupport() (optional, available from version 1.1).\ This method is necessary to detect mobile browsers in Desktop Mode condition (Android and iOS).\ For Desktop Mode detection setTouchSupport() method should call if browser supports Touch events.\ Touch events detection is performed by client-side JavaScript code in the target browser. Example:

Description for returned variables

OS Type (os_type)\ Returns type of operating system (OS).\ All possible values:

OS Family (os_family)\ Returns operating system (OS) family or unknown in cases of unable OS family recognition.\ Example: windows, linux, unix etc.

OS Name (os_name)\ Returns operating system (OS) name or unknown in cases of unable OS name recognition.\ Example: Windows, Android, macOS, iOS etc.

OS Version (os_version)\ Returns operating system (OS) version or 0 in cases of unable OS version recognition.\ May contains numeric, string or mixed types OS versions.\ In case of numeric OS version (e.g. Android) contains major and minor version parts values, e.g. 4.4, 8.1, 10 etc.\ In case of string OS version (e.g. macOS) contains string version name values, e.g. Mavericks, Mojave, Catalina etc.\ For Windows may contains mixed version types values: 10, Vista, XP etc.

OS Title (os_title)\ Returns operating system (OS) title which contains OS name and OS version together.\ Also returns unknown if OS name is not recognized.

Device Type (device_type)\ Returns device type based on some User-Agent data.\ All possible values:

Browser Name (browser_name)\ Returns browser name or unknown in cases of unable browser name recognition.\ Example: Chrome, Firefox, UC Browser, Huawei Browser, Vivaldi etc.

Browser Version (browser_version)\ Returns browser version number or 0 in cases of unable browser version recognition.\ Always contains numeric values (integer or float numbers).\ Returns float number (e.g. 3.5, 10.5, 13.1) for some browsers which should contains both major and minor browser version parts (Safari, Vivaldi, PaleMoon etc).\ Returns only major decimal browser version (e.g. 15, 37, 81) for other browsers which has a lot of major versions (Chrome, Firefox, Opera etc).

Browser Title (browser_title)\ Returns browser title which contains browser name and browser version together.\ Also returns unknown if browser name is not recognized.

Browser Chrome Original (browser_chrome_original)\ Returns 1 number if browser recognized as original Google Chrome browser or returns 0 if it's not.

Browser Firefox Original (browser_firefox_original)\ Returns 1 number if browser recognized as original Mozilla Firefox browser or returns 0 if it's not.

Browser Safari Original (browser_safari_original)\ Returns 1 number if browser recognized as original Apple Safari browser or returns 0 if it's not.

Browser Chromium Version (browser_chromium_version)\ Returns Chromium major engine version number if browser based on Chromium engine or returns 0 if it's not.

Browser Gecko Version (browser_gecko_version)\ Returns Gecko major engine version number if browser based on Gecko engine or returns 0 if it's not.

Browser WebKit Version (browser_webkit_version)\ Returns WebKit version engine number if browser based on WebKit engine or returns 0 if it's not.\ Always float number value.

Browser Android Webview (browser_android_webview)\ Returns 1 number if Android Webview mode detected or returns 0 if it's not.

Browser iOS Webview (browser_ios_webview)\ Returns 1 number if iOS Webview mode detected or returns 0 if it's not.

Browser Desktop Mode (browser_desktop_mode)\ Returns 1 number if mobile browser works in Desktop Mode or returns 0 if it's not detected.\ setTouchSupport() method should call for Desktop Mode detection if browser supports Touch events.

64 Bits Mode (64bits_mode)\ Returns 1 number if operating system (OS) and browser work together in 64-bit mode or returns 0 if 64-bit mode not detected.\ Available only for getAll(); and getOS(); methods.

Usage Examples

See follow examples to understand library usage use cases.

Detect All

To detect all possible environment data use:

Returns:

OS Detection

To parse only OS data use:

Returns:

Browser Detection

To parse only browser data use:

Returns:

Device Detection

To parse only device type data use:

Returns:

Desktop Mode Detection

To detect if mobile browser works in Desktop Mode use:

Returns:

Detect All (JSON)

To pasre all possible environment data and returns JSON format string:

Returns:

Benchmarking Test

Benchmarking was performed on a low-level shared hosting.\ Test server configuration: RedHat Linux + LiteSpeed + PHP Extension.\ Test conditions based on collection of random ~446000 non repeated real life User-Agent strings.

User-Agent recognition performance in PHP 7.3 (requests per second):

License

The MIT License (MIT)

Copyright (c) 2020-2023 Artem Murugov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


All versions of php-browser-detection with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package foroco/php-browser-detection contains the following files

Loading the files please wait ....