-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.php
executable file
·161 lines (129 loc) · 5.67 KB
/
example.php
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
<?php
/*
<XBD, Extended Browser Detection.>
Copyright (C) <2009> <Guillermo Azurdia, www.nopticon.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once('./xbd.php');
// -----------------------------------------------------------------------------------
// NOTES:
//
//
// This library also can handle browser detection of cellphones,
// basic spiders and games consoles!
//
// Cellphones: Nokia, Motorola, Samsung, Sony Ericsson, Blackberry, iPhone and HTC.
// Game consoles: Wii and Playstation
//
// If you need to detect IE, when calling the function must use "msie".
// ("ie" won't work.)
//
// 'version_compare' function is used so you can use the same operator syntax
// http://www.php.net/manual/en/function.version-compare.php
//
// The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively.
//
// * XBD 1.1 *
// ==
//
// After a request by email about how to detect OS X version, I've added
// a new argument to return array data based on first argument.
// -----------------------------------------------------------------------------------
// Return array of browser data
$ret = _browser();
_print('All', $ret);
$ret = _browser('*');
_print('Useragent string', $ret);
// Return true if using firefox
$ret = _browser('firefox');
_print('Firefox', $ret);
// Return true if using IE 7.0 or above else false
$ret = _browser('msie', '>= 7.0');
_print('MSIE >= 7.0', $ret);
// Return true if using below firefox 3.0.5 (can check minor version)
$ret = _browser('firefox', '< 3.0.5');
_print('Firefox < 3.0.5', $ret);
// Return string of name of browser and version
$ret = _browser(false, false, true);
_print('Browser and version', $ret);
// To check if Gecko browser is used
$ret = _browser('gecko');
_print('Is Gecko?', $ret);
$ret = _browser('firefox', 'le 1.5');
_print('Operator by name (Checking Firefox le 1.5)', $ret);
$ret = _browser('firefox', 'ge 3.5.1');
_print('Operator by name (Checking Firefox ge 3.5.1)', $ret);
// -----------------------------------------------------------------------------------
// XBD 1.1 tests.
// -----------------------------------------------------------------------------------
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5';
$ret = _browser();
_print('Mac useragent', $ret);
// -----------------------------------------------------------------------------------
// XBD 1.0, can return (string) OS X version.
// Or if using OS X (bool)
//
// XBD 1.1, can return an (array) based on first arg.
// -----------------------------------------------------------------------------------
$ret = _browser('os x', false, true);
_print('OS X string', $ret);
$ret = _browser('os x');
_print('OS X bool', $ret);
$ret = _browser('os x', false, false, false, true);
_print('Mac OS X array', $ret);
// -----------------------------------------------------------------------------------
// How to know the Windows version from the client?
//
// I found a useful information page from Microsoft explaining the user agent strings here:
// http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx
//
// So, getting the "Windows NT" part from the useragent, we can known the Windows version :-)
// -----------------------------------------------------------------------------------
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9b2pre) Gecko/2007120505 Minefield/3.0b2pre';
$ret = _browser('windows nt', false, false, false, true);
_print('Windows array', $ret);
$windows_array = array(
'6.1' => 'Windows 7',
'6.0' => 'Windows Vista',
'5.2' => 'Windows Server 2003 or Windows XP x64',
'5.1' => 'Windows XP'
);
if (isset($windows_array[$ret['version']])) {
_print('Client is using', $windows_array[$ret['version']]);
} else {
_print('Windows version not found.');
}
// -----------------------------------------------------------------------------------
// Detect if Windows version is below or above a determined version.
// Based on $windows_array you can determine the version number for the condition.
// -----------------------------------------------------------------------------------
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b2pre) Gecko/2007120505 Minefield/3.0b2pre';
$windows_array = array(
'6.1' => 'Windows 7',
'6.0' => 'Windows Vista',
'5.2' => 'Windows Server 2003 or Windows XP x64',
'5.1' => 'Windows XP'
);
$ret = _browser('windows nt', false, false, false, true);
if (isset($ret['version']) && !empty($ret['version'])) {
$detect_by_name = 'Windows Vista';
$detect_by_number = array_search($detect_by_name, $windows_array);
if ($ret['version'] == $detect_by_number) {
_print('Detected version (' . $windows_array[$ret['version']] . ') is equal to ' . $windows_array[$detect_by_number]);
} elseif ($ret['version'] <= $detect_by_number) {
_print('Detected version ' . $windows_array[$ret['version']] . ' is below to ' . $windows_array[$detect_by_number]);
} else {
_print('Detected version ' . $windows_array[$ret['version']] . ' is above to ' . $windows_array[$detect_by_number]);
}
} else {
_print('Windows version not found.');
}