mobiledetect/mobiledetectlib
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
psr/simple-cache | 3.0.0 | 4.48 kB | MIT | prod |
Mobile Detect, also known as mobiledetect/mobiledetectlib, is a lightweight PHP class that performs mobile device detection. It uses the User-Agent string along with specific HTTP headers to identify the mobile environment. This library provides a server-side detection mechanism that assists in distinguishing between a mobile phone and a tablet through the use of regular expressions. The class ensures detection accuracy and relevance by running tests to check for detection conflicts. It provides crucial support in implementing a responsive web design strategy and can be used along with CSS3 media queries and other client-side feature detection methods.
Usage of mobiledetect/mobiledetectlib is straightforward. It starts with the installation via composer by using the command composer require mobiledetect/mobiledetectlib
. To include the dependency in your PHP project, you should add "mobiledetect/mobiledetectlib": "^4.8"
under the require
section in the composer.json
file. To detect a mobile device, you can instantiate the MobileDetect
class and set the user agent string. The isMobile()
and isTablet()
methods can be used to determine the device type.
Here's an illustrative example:
// Include composer's autoloader
require __DIR__ . '/vendor/autoload.php';
use Detection\MobileDetect;
// Instantiate the class
$detect = new MobileDetect;
// Set the user agent string from HTTP headers
$detect->setUserAgent('Mozilla/5.0 (iPad; CPU OS 14_7 like Mac OS X) ...');
// Check for "mobile"
$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'computer');
In this example, the $deviceType
variable will contain the type of the detected device.
You can find the comprehensive documentation for mobiledetect/mobiledetectlib on the project's GitHub repository. The readme file contains detailed explanations about its installation, usage, features, and potential performance. Furthermore, it provides the structure of the project along with test execution details. You can contribute to the project, access several modules, plugins, ports, and check out its considerable history.