docs
2 years ago
lib
2 years ago
LICENSE.LGPL-3.0-only.md
2 years ago
LICENSE.MIT.md
2 years ago
LICENSE.md
2 years ago
README.md
2 years ago
composer.json
1 year ago
README.md
112 lines
| 1 | BrowserDetection |
| 2 | ================ |
| 3 | |
| 4 | The [](https://wolfcast.com/Wolfcast](https://wolfcast.com/](https://wolfcast.com/) BrowserDetection PHP class facilitates the identification of the user's environment such as Web browser, version, platform family, platform version or if it's a mobile device or not. |
| 5 | |
| 6 | This class will try to detect what the user is using from the `HTTP_USER_AGENT` string sent by the Web browser. A good way to use the class would be to gather user statistics or to report the browser and version used for informational purposes. A bad way to use the class would be to serve content based on the browser and version used. **Sites that rely on the user-agent string should be updated to modern techniques, such as feature detection, adaptive layout, and other modern practices.** |
| 7 | |
| 8 | Always keep in mind that `HTTP_USER_AGENT` can be easily spoofed by the user. |
| 9 | |
| 10 | Features |
| 11 | -------- |
| 12 | |
| 13 | The [](https://wolfcast.com/Wolfcast](https://wolfcast.com/](https://wolfcast.com/) BrowserDetection PHP class is the most accurate detection class. **It has been tested with 14000+ different user agent strings and it have a 99.95% accuracy ratio!** |
| 14 | |
| 15 | Natively detects the following browsers: |
| 16 | |
| 17 | * Android |
| 18 | * BlackBerry |
| 19 | * BlackBerry Tablet OS |
| 20 | * Chrome |
| 21 | * Edge |
| 22 | * Firebird |
| 23 | * Firefox |
| 24 | * GNU IceCat |
| 25 | * GNU IceWeasel |
| 26 | * iCab |
| 27 | * Internet Explorer |
| 28 | * Internet Explorer Mobile |
| 29 | * Konqueror |
| 30 | * Lynx |
| 31 | * Mozilla |
| 32 | * MSN TV |
| 33 | * Netscape |
| 34 | * Nokia Browser |
| 35 | * Opera |
| 36 | * Opera Mini |
| 37 | * Opera Mobile |
| 38 | * Phoenix |
| 39 | * Safari |
| 40 | * Samsung Internet |
| 41 | * UC Browser |
| 42 | |
| 43 | You can also easily add custom rules to support other browsers not natively supported! |
| 44 | |
| 45 | Natively detects the following robots: |
| 46 | |
| 47 | * Bingbot |
| 48 | * Googlebot |
| 49 | * MSNBot |
| 50 | * W3C Validator |
| 51 | * Yahoo! Multimedia |
| 52 | * Yahoo! Slurp |
| 53 | |
| 54 | You can also easily add custom rules to support other robots not natively supported! |
| 55 | |
| 56 | Natively detects the following platforms: |
| 57 | * Android |
| 58 | * BlackBerry |
| 59 | * Chrome OS |
| 60 | * FreeBSD |
| 61 | * iOS |
| 62 | * Linux |
| 63 | * Macintosh |
| 64 | * NetBSD |
| 65 | * Nokia |
| 66 | * OpenBSD |
| 67 | * OpenSolaris |
| 68 | * Symbian |
| 69 | * Windows |
| 70 | * Windows CE |
| 71 | * Windows Phone |
| 72 | |
| 73 | You can also easily add custom rules to support other platforms not natively supported! |
| 74 | |
| 75 | Requirements |
| 76 | ------------ |
| 77 | |
| 78 | Requires PHP 5.3 or newer (tested with PHP 8.1.0, 7.4.26 and 5.6.40). |
| 79 | |
| 80 | Demo and full documentation |
| 81 | --------------------------- |
| 82 | |
| 83 | You can try the [](https://wolfcast.com/open-source/browser-detection/tutorial.phplive demo](https://wolfcast.com/open-source/browser-detection/tutorial.php](https://wolfcast.com/open-source/browser-detection/tutorial.php) of the class and you can read the [](https://wolfcast.com/open-source/browser-detection/doc/Browser_Detection/BrowserDetection.htmldocumentation](https://wolfcast.com/open-source/browser-detection/doc/Browser_Detection/BrowserDetection.html](https://wolfcast.com/open-source/browser-detection/doc/Browser_Detection/BrowserDetection.html). |
| 84 | |
| 85 | Installation |
| 86 | ------------ |
| 87 | |
| 88 | To install, simply upload `BrowserDetection.php` (found in the `lib` directory) to your web host and `require_once` it in your PHP script. |
| 89 | |
| 90 | Usage |
| 91 | ----- |
| 92 | |
| 93 | ``` |
| 94 | require_once('BrowserDetection.php'); |
| 95 | |
| 96 | $browser = new Wolfcast\BrowserDetection(); |
| 97 | if ($browser->getName() == Wolfcast\BrowserDetection::BROWSER_FIREFOX && |
| 98 | $browser->compareVersions($browser->getVersion(), '5.0') >= 0) { |
| 99 | echo 'You are using FireFox version 5 or greater.'; |
| 100 | } |
| 101 | ``` |
| 102 | |
| 103 | History |
| 104 | ------- |
| 105 | |
| 106 | Correctly identifying what Web browser your users are using is an incredibly complex task. If you ever tried to implement something like this you quickly saw how this can become a code mess. Only a few libraries exist and they often get deprecated and becomes abandonware. This is why we created our own detection engine. We didn't start from scratch. The class is a heavily updated version of Chris Schuld's Browser class version 1.9 (which was unmaintained for a couple of years). Chris' class was based on the original work from Gary White. |
| 107 | |
| 108 | License |
| 109 | ------- |
| 110 | |
| 111 | SPDX-License-Identifier: MIT OR LGPL-3.0-only |
| 112 |