-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOs.php
More file actions
196 lines (191 loc) · 8.57 KB
/
Os.php
File metadata and controls
196 lines (191 loc) · 8.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/*******************************************************************************
* Copyright (c) 2022. Ankio. All Rights Reserved.
******************************************************************************/
/**
* Package: library\useragent
* Class Os
* Created By ankio.
* Date : 2023/7/13
* Time : 21:05
* Description :
*/
namespace library\useragent;
class Os
{
static function get($ua)
{
$version = null;
$code = null;
if (preg_match('/Windows/i', $ua) || preg_match('/WinNT/i', $ua) || preg_match('/Win32/i', $ua)) {
$title = 'Windows';
if (preg_match('/Windows NT 10.0/i', $ua) || preg_match('/Windows NT 6.4/i', $ua)) {
$version = '10';
$code = 'Windows-10';
} elseif (preg_match('/Windows NT 6.3/i', $ua)) {
$version = '8.1';
$code = 'Windows-8';
} elseif (preg_match('/Windows NT 6.2/i', $ua)) {
$version = '8';
$code = 'Windows-8';
} elseif (preg_match('/Windows NT 6.1/i', $ua)) {
$version = '7';
} elseif (preg_match('/Windows NT 6.0/i', $ua)) {
$version = 'Vista';
} elseif (preg_match('/Windows NT 5.2 x64/i', $ua)) {
$version = 'XP'; // x64 Edition very similar to Win 2003
} elseif (preg_match('/Windows NT 5.2/i', $ua)) {
$version = 'Server 2003';
} elseif (preg_match('/Windows NT 5.1/i', $ua) || preg_match('/Windows XP/i', $ua)) {
$version = 'XP';
} elseif (preg_match('/Windows NT 5.01/i', $ua)) {
$version = '2000 (SP1)';
} elseif (preg_match('/Windows NT 5.0/i', $ua) || preg_match('/Windows NT5/i', $ua) || preg_match('/Windows 2000/i', $ua)) {
$version = '2000';
} elseif (preg_match('/Windows NT 4.0/i', $ua) || preg_match('/WinNT4.0/i', $ua)) {
$version = 'NT 4.0';
} elseif (preg_match('/Windows NT 3.51/i', $ua) || preg_match('/WinNT3.51/i', $ua)) {
$version = 'NT 3.11';
} elseif (preg_match('/Windows NT/i', $ua) || preg_match('/WinNT/i', $ua)) {
$version = 'NT';
} elseif (preg_match('/Windows 3.11/i', $ua) || preg_match('/Win3.11/i', $ua) || preg_match('/Win16/i', $ua)) {
$version = '3.11';
} elseif (preg_match('/Windows 3.1/i', $ua)) {
$version = '3.1';
} elseif (preg_match('/Windows 98; Win 9x 4.90/i', $ua) || preg_match('/Win 9x 4.90/i', $ua) || preg_match('/Windows ME/i', $ua)) {
$version = 'ME';
} elseif (preg_match('/Win98/i', $ua)) {
$version = '98 SE';
} elseif (preg_match('/Windows 98/i', $ua) || preg_match('/Windows\ 4.10/i', $ua)) {
$version = '98';
} elseif (preg_match('/Windows 95/i', $ua) || preg_match('/Win95/i', $ua)) {
$version = '95';
} elseif (preg_match('/Windows CE/i', $ua)) {
$version = 'CE';
} elseif (preg_match('/WM5/i', $ua)) {
$version = 'Mobile 5';
} elseif (preg_match('/WindowsMobile/i', $ua)) {
$version = 'Mobile';
}
} elseif (preg_match('/Android/i', $ua)) {
$title = 'Android';
if (preg_match('/Android[\ |\/]?([.0-9a-zA-Z]+)/i', $ua, $regmatch)) {
$version = $regmatch[1];
}
} elseif (preg_match('/Mac/i', $ua) || preg_match('/Darwin/i', $ua)) {
$title = 'Mac OS X';
$code = 'Apple';
if (preg_match('/Mac OS X/i', $ua) || preg_match('/Mac OSX/i', $ua)) {
if (preg_match('/iPhone/i', $ua)) {
$title = 'iOS';
$version = substr($ua, strpos(strtolower($ua), strtolower('iPhone OS')) + 10);
// Parse iOS version number
$version = substr($version, 0, strpos($version, 'l') - 1);
} elseif (preg_match('/iPad/i', $ua)) {
$title = 'iOS';
$version = substr($ua, strpos(strtolower($ua), strtolower('CPU OS')) + 7);
$version = substr($version, 0, strpos($version, 'l') - 1);
} elseif (preg_match('/Mac OS X/i', $ua)) {
$version = substr($ua, strpos(strtolower($ua), strtolower('OS X')) + 5);
// Parse OS X version number
$version = substr($version, 0, strpos($version, ')'));
} else {
$version = substr($ua, strpos(strtolower($ua), strtolower('OSX')) + 4);
$version = substr($version, 0, strpos($version, ')'));
}
// Parse OS X version number
if (strpos($version, ';') > -1) {
$version = substr($version, 0, strpos($version, ';'));
}
// Beautify version format
$version = str_replace('_', '.', $version);
} elseif (preg_match('/Darwin/i', $ua)) {
$title = 'Mac OS Darwin';
} else {
$title = 'Macintosh';
}
} elseif (preg_match('/[^A-Za-z]Arch/i', $ua)) {
$title = 'Arch Linux';
$code = 'Arch-Linux';
} elseif (preg_match('/BlackBerry/i', $ua)) {
$title = 'BlackBerryOS';
} elseif (preg_match('/CentOS/i', $ua)) {
$title = 'CentOS';
if (preg_match('/.el([.0-9a-zA-Z]+).centos/i', $ua, $regmatch)) {
$version = $regmatch[1];
}
} elseif (preg_match('/CrOS/i', $ua)) {
$title = 'Google Chrome OS';
$code = 'Chrome-OS';
} elseif (preg_match('/Debian/i', $ua)) {
$title = 'Debian GNU/Linux';
$code = 'Debian';
} elseif (preg_match('/Fedora/i', $ua)) {
$title = 'Fedora';
if (preg_match('/.fc([.0-9a-zA-Z]+)/i', $ua, $regmatch)) {
$version = $regmatch[1];
}
} elseif (preg_match('/FreeBSD/i', $ua)) {
$title = 'FreeBSD';
} elseif (preg_match('/OpenBSD/i', $ua)) {
$title = 'OpenBSD';
} elseif (preg_match('/Oracle/i', $ua)) {
$title = 'Oracle';
$code = 'Oracle-Linux';
if (preg_match('/.el([._0-9a-zA-Z]+)/i', $ua, $regmatch)) {
$title .= ' Enterprise Linux';
$version = str_replace('_', '.', $regmatch[1]);
} else {
$title .= ' Linux';
}
} elseif (preg_match('/Red\ Hat/i', $ua) || preg_match('/RedHat/i', $ua)) {
$title = 'Red Hat';
$code = 'Red-Hat';
if (preg_match('/.el([._0-9a-zA-Z]+)/i', $ua, $regmatch)) {
$title .= ' Enterprise Linux';
$version = str_replace('_', '.', $regmatch[1]);
}
} elseif (preg_match('/Solaris/i', $ua) || preg_match('/SunOS/i', $ua)) {
$title = 'Solaris';
} elseif (preg_match('/Symb[ian]?[OS]?/i', $ua)) {
$title = 'SymbianOS';
if (preg_match('/Symb[ian]?[OS]?\/([.0-9a-zA-Z]+)/i', $ua, $regmatch)) {
$version = $regmatch[1];
}
} elseif (preg_match('/Ubuntu/i', $ua)) {
$title = 'Ubuntu';
if (preg_match('/Ubuntu[\/|\ ]([.0-9]+[.0-9a-zA-Z]+)/i', $ua, $regmatch)) {
$version = $regmatch[1];
}
} elseif (preg_match('/Linux/i', $ua)) {
$title = 'GNU/Linux';
$code = 'Linux';
} elseif (preg_match('/J2ME\/MIDP/i', $ua)) {
$title = 'J2ME/MIDP Device';
$code = 'Java';
} // No OS match
else {
$title = 'Other System';
$code = 'Others';
}
// Check x64 architecture
if (preg_match('/x86_64/i', $ua)) {
// If version isn't null append 64 bit, otherwise set it to x64
$version = (is_null($version)) ? 'x64' : "$version x64";
} elseif ((preg_match('/Windows/i', $ua) || preg_match('/WinNT/i', $ua) || preg_match('/Win32/i', $ua))
&& (preg_match('/Win64/i', $ua) || preg_match('/x64/i', $ua) || preg_match('/WOW64/i', $ua))
) {
$version .= ' x64 Edition';
}
if (is_null($code)) {
$code = $title;
}
// Append version to title
if (isset($version)) {
$title .= " $version";
}
$result['code'] = $code;
$result['title'] = $title;
return $result;
}
}