forked from swooningfish/getBrowserOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetBrowserOS.php
More file actions
94 lines (81 loc) · 4.88 KB
/
Copy pathgetBrowserOS.php
File metadata and controls
94 lines (81 loc) · 4.88 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
<?php
##################################################
# #
# getBrowserOS.php by Joe Mottershaw #
# Cloud Eight - http://www.cloud-eight.com #
# #
##################################################
// Assign user agent string to variable
$userAgent = $_SERVER['HTTP_USER_AGENT'];
// Function fetch the operating system
function getOS()
{
global $userAgent;
$os = 'Unknown OS';
$osArray = array(
'/windows nt 6.2/i' => 'Windows 8',
'/windows nt 6.1/i' => 'Windows 7',
'/windows nt 6.0/i' => 'Windows Vista',
'/windows nt 5.2/i' => 'Windows Server 2003/XP x64',
'/windows nt 5.1/i' => 'Windows XP',
'/windows xp/i' => 'Windows XP',
'/windows nt 5.0/i' => 'Windows 2000',
'/windows me/i' => 'Windows ME',
'/win98/i' => 'Windows 98',
'/win95/i' => 'Windows 95',
'/win16/i' => 'Windows 3.11',
'/macintosh|mac os x/i' => 'Mac OS X',
'/mac_powerpc/i' => 'Mac OS 9',
'/linux/i' => 'Linux',
'/ubuntu/i' => 'Ubuntu',
'/webos|mobile|tablet/i' => 'Mobile/Tablet Device',
'/iphone/i' => 'iPhone',
'/ipod/i' => 'iPod',
'/ipad/i' => 'iPad',
'/windows phone/i' => 'Windows Phone',
'/htc/i' => 'HTC',
'/(?=.*htc)(?=.*android)/i' => 'HTC Android',
'/(?=.*htc)(?=.*windows phone)/i' => 'HTC Windows Phone',
'/blackberry/i' => 'BlackBerry',
'/kindle/i' => 'Kindle',
'/playstation 3/i' => 'Playstation 3',
'/psp|playstation portable/i' => 'PSP'
);
foreach ($osArray as $regex => $value)
{
if (preg_match($regex, $userAgent))
{
$os = $value;
}
}
return $os;
}
// Function to fetch the browser
function getBrowser()
{
global $userAgent;
$browser = 'Unknown Browser';
$browserArray = array(
'/playstation 3|psp|playstation portable|net front/i' => 'Sony PS/Access NetFront',
'/xbox/i' => 'Microsoft Xbox',
'/webkit|gecko/i' => 'Unknown WebKit/Gecko Based Browser',
'/msie/i' => 'Internet Explorer',
'/firefox/i' => 'Firefox',
'/safari/i' => 'Safari',
'/chrome/i' => 'Chrome',
'/opera/i' => 'Opera',
'/netscape/i' => 'Netscape',
'/maxthon/i' => 'Maxthon',
'/konqueror/i' => 'Konqueror',
'/webos|mobile|tablet|kindle/i' => 'Mobile/Tablet Browser'
);
foreach ($browserArray as $regex => $value)
{
if (preg_match($regex, $userAgent))
{
$browser = $value;
}
}
return $browser;
}
?>