Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e1e7a2

Browse files
committed
Version 2.2 (release)
MacOS Monterey and Windows 11 User-Agents detection
1 parent a5fcdab commit 5e1e7a2

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

‎CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this `PHP Browser Detection` project documented in this file.
44

5+
## [2.2] - 2021年07月05日
6+
7+
### Added
8+
9+
- MacOS Monterey detection added;
10+
- Windows 11 detection added.
11+
512
## [2.1] - 2021年04月06日
613

714
### Changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Uses a simple and fast algorithm to accurately detect more than 165 browser type
66
For most commonly browsers parsing process took less than 0.0005 second even on low-level shared hosting.\
77
In the case of rare User-Agents recognized time is less than 0.0008 second for the same conditioned hosting environment.\
88
The library supports only really actual Browsers and OS without support for outdated environments that are actually not used now.\
9+
Newest MacOS Monterey and Windows 11 User-Agents detection included.\
910
Works by use only one library file and without any third-party libraries dependency.
1011

1112
## Requirements

‎src/BrowserDetection.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2626
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2727
*
28-
* @version 2.1
29-
* @last-modified April 6, 2021
28+
* @version 2.2
29+
* @last-modified July 5, 2021
3030
* @link https://github.com/foroco/php-browser-detection
3131
*/
3232

@@ -245,6 +245,7 @@ private function macos_codename($version)
245245
case 14: $result_codename = 'Mojave'; break;
246246
case 15: $result_codename = 'Catalina'; break;
247247
case 16: $result_codename = 'Big Sur'; break;
248+
case 17: $result_codename = 'Monterey'; break;
248249
default: $result_codename = 'New'; break;
249250
}
250251
return $result_codename;
@@ -314,6 +315,8 @@ private function getResult()
314315
$this->result_os_name = 'Windows';
315316
$matches = $this->match_ua('/Windows ([ .a-zA-Z0-9]+)[;\\)]/');
316317
$version = is_array($matches) ? $matches[1] : 0;
318+
if ($version === 'NT 11.0') $this->result_os_version = '11';
319+
if ($version === 'NT 10.1') $this->result_os_version = '11';
317320
if ($version === 'NT 10.0') $this->result_os_version = '10';
318321
if ($version === 'NT 6.4') $this->result_os_version = '10';
319322
if ($version === 'NT 6.3') $this->result_os_version = '8.1';
@@ -372,10 +375,13 @@ private function getResult()
372375
$version = is_array($matches) ? $matches[1] : 0;
373376
$version_minor = is_array($matches) ? $matches[2] : 0;
374377

378+
// macOS version to minor version conversion (needs since Big Sur)
375379
if ($version == 11) $version_minor = 16;
380+
if ($version == 12) $version_minor = 17;
381+
376382
if (!empty($version_minor))
377383
{
378-
if ($version == 10 || $version == 11) $this->result_os_version = $this->macos_codename($version_minor);
384+
if ($version >= 10) $this->result_os_version = $this->macos_codename($version_minor);
379385
$this->macos_version_minor = $version_minor;
380386
}
381387

‎tests/v2.2.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
require_once('../src/BrowserDetection.php');
4+
$Browser = new foroco\BrowserDetection();
5+
6+
// Testing some new User-Agent strings
7+
8+
$useragent[] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 12_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36';
9+
$useragent[] = 'Mozilla/5.0 (Windows NT 10.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36';
10+
$useragent[] = 'Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36';
11+
12+
$time_start = microtime(true);
13+
14+
foreach ($useragent as $u)
15+
{
16+
// Detect all possible environment data from User-Agents
17+
$result = $Browser->getAll($u);
18+
19+
echo '<div style="font-size:16px; font-weight:bold"><pre>';
20+
echo $u;
21+
echo '</pre></div>';
22+
23+
echo '<div style="font-size:18px; font-weight:bold"><pre>';
24+
print_r($result);
25+
echo '</pre></div>';
26+
27+
echo '<div style="font-size:16px; font-weight:bold"><pre>';
28+
echo '--------------------------------------------------------------------------------';
29+
echo '</pre></div>';
30+
31+
}
32+
33+
$time_end = microtime(true);
34+
$time_result = $time_end - $time_start;
35+
36+
echo '<p style="font-size:21px">Total execution time: '.substr($time_result,0,7).' sec.</p>';
37+
38+
?>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /