dbXapp
2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Toggle main menu visibility
Loading...
Searching...
No Matches
dbxBrowser.class.php
Go to the documentation of this file.
1
<?php
2
3
class
dbxBrowser
{
4
public
$_device
=
'desktop'
;
5
public
$_agent
=
''
;
6
public
$_language
=
''
;
7
public
$_name
=
''
;
8
public
$_version
=
''
;
9
public
$_platform
=
''
;
10
public
$_aol
= 0;
11
public
$_mobile
= 0;
12
public
$_ipad
= 0;
13
public
$_robot
= 0;
14
public
$_width
= 0;
15
public
$_height
= 0;
16
public
$_cookie
= 0;
17
public
$_iframe
= 0;
18
public
$_js
= 0;
19
public
$_java
= 0;
20
public
$_flasch
= 0;
21
public
$_host
=
'host'
;
22
public
$_ip
=
'ip'
;
23
private
$_is_robot=0;
24
25
26
public
function
init
() {
27
28
$this->_agent = isset(
$_SERVER
[
'HTTP_USER_AGENT'
]) ?
$_SERVER
[
'HTTP_USER_AGENT'
] :
""
;
29
30
$this->
get_ip
();
31
$this->
get_host
($this->_ip);
32
33
$this->
checkLanguage
();
34
$this->
checkPlatform
();
35
$this->
checkBrowsers
();
36
$this->
checkForSize
();
37
$this->
checkForIntPad
();
38
$this->
checkForRobot
();
39
$this->
checkMobile
();
40
}
41
42
public
function
__construct
() {
43
$this->
init
();
44
}
45
46
47
public
function
isBrowser
($browserName) {
48
return
(0 == strcasecmp($this->_name, trim($browserName)));
49
}
50
51
protected
function
setVersion
($version) {
52
$this->_version = preg_replace(
'/[^0-9a-zA-Z\.]/'
,
''
,$version);
53
}
54
55
protected
function
setPlatform
($os) {
56
$this->_platform = $os;
57
}
58
59
60
/* =====================================================
61
* MOBILE (NEU & STABIL)
62
* ===================================================== */
63
public
function
checkMobile
() {
64
65
$ua = strtolower($this->_agent);
66
67
$is_mobile = 0;
68
$device =
'desktop'
;
69
70
if
($ua) {
71
72
/* =========================================
73
* 1. TABLETS
74
* ========================================= */
75
if
(
76
strpos($ua,
'ipad'
) !==
false
||
77
(strpos($ua,
'android'
) !==
false
&& strpos($ua,
'mobile'
) ===
false
) ||
78
strpos($ua,
'tablet'
) !==
false
||
79
strpos($ua,
'kindle'
) !==
false
||
80
strpos($ua,
'silk'
) !==
false
81
) {
82
$is_mobile = 1;
83
$device =
'tablet'
;
84
$this->_ipad = 1;
85
}
86
87
/* =========================================
88
* 2. PHONES
89
* ========================================= */
90
elseif (
91
strpos($ua,
'iphone'
) !==
false
||
92
strpos($ua,
'ipod'
) !==
false
||
93
strpos($ua,
'android'
) !==
false
||
94
strpos($ua,
'blackberry'
) !==
false
||
95
strpos($ua,
'bb10'
) !==
false
||
96
strpos($ua,
'windows phone'
) !==
false
||
97
strpos($ua,
'opera mini'
) !==
false
||
98
strpos($ua,
'opera mobi'
) !==
false
99
) {
100
$is_mobile = 1;
101
$device =
'phone'
;
102
}
103
104
/* =========================================
105
* 3. GENERISCH MOBILE
106
* ========================================= */
107
elseif (
108
strpos($ua,
'mobile'
) !==
false
||
109
strpos($ua,
'mobi'
) !==
false
110
) {
111
$is_mobile = 1;
112
$device =
'phone'
;
113
}
114
115
/* =========================================
116
* 4. FALLBACK (Touch/WebKit Geräte)
117
* ========================================= */
118
elseif (
119
strpos($ua,
'webkit'
) !==
false
&&
120
(
121
strpos($ua,
'touch'
) !==
false
||
122
strpos($ua,
'phone'
) !==
false
123
)
124
) {
125
$is_mobile = 1;
126
$device =
'phone'
;
127
}
128
}
129
130
// State setzen (kompatibel!)
131
$this->_mobile = $is_mobile;
132
$this->_device = $device;
133
134
dbx
()->set_system_var(
'dbx_is_mobile'
,$is_mobile);
135
dbx
()->set_system_var(
'dbx_device'
,$device);
136
137
return
$is_mobile;
138
}
139
140
141
/* =====================================================
142
* IP
143
* ===================================================== */
144
public
function
get_ip
() {
145
146
$candidates = array();
147
148
foreach
(array(
'HTTP_CLIENT_IP'
,
'HTTP_X_FORWARDED_FOR'
,
'HTTP_X_REAL_IP'
,
'REMOTE_ADDR'
) as $key) {
149
if
(empty(
$_SERVER
[$key])) {
150
continue
;
151
}
152
153
foreach
(explode(
','
, (
string
)
$_SERVER
[$key]) as $part) {
154
$candidates[] = $part;
155
}
156
}
157
158
$this->_ip =
'0.0.0.0'
;
159
160
foreach
($candidates as $candidate) {
161
$ip = $this->
normalize_ip
($candidate);
162
if
($ip !==
''
) {
163
$this->_ip = $ip;
164
break
;
165
}
166
}
167
}
168
169
protected
function
normalize_ip
($ip) {
170
$ip = trim((
string
) $ip);
171
172
if
($ip ===
''
|| strtolower($ip) ===
'unknown'
) {
173
return
''
;
174
}
175
176
if
(str_starts_with($ip,
'['
)) {
177
$end = strpos($ip,
']'
);
178
if
($end !==
false
) {
179
$ip = substr($ip, 1, $end - 1);
180
}
181
} elseif (substr_count($ip,
':'
) === 1 && preg_match(
'/^([0-9.]+):[0-9]+$/'
, $ip, $m)) {
182
$ip = $m[1];
183
}
184
185
// IPv6 localhost auf IPv4 localhost normalisieren
186
if
($ip ===
'::1'
|| $ip ===
'0:0:0:0:0:0:0:1'
) {
187
return
'127.0.0.1'
;
188
}
189
190
// IPv4-mapped IPv6 normalisieren, z.B. ::ffff:127.0.0.1
191
if
(preg_match(
'/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i'
, $ip, $m)) {
192
$ip = $m[1];
193
}
194
195
return
filter_var($ip, FILTER_VALIDATE_IP) ? $ip :
''
;
196
}
197
198
199
protected
function
get_host
($ip) {
200
$this->_host =
''
;
201
202
$ip = trim((
string
) $ip);
203
204
if
($ip ===
'127.0.0.1'
|| $ip ===
'::1'
) {
205
$this->_host =
'localhost'
;
206
return
;
207
}
208
209
$this->_host = $ip;
210
}
211
212
213
protected
function
checkLanguage
() {
214
if
(isset(
$_SERVER
[
'HTTP_ACCEPT_LANGUAGE'
])) {
215
$this->_language = substr(
$_SERVER
[
'HTTP_ACCEPT_LANGUAGE'
], 0, 2);
216
}
217
}
218
219
220
protected
function
checkForIntPad
() {
221
if
(stripos($this->_agent,
'ipad'
) !==
false
) {
222
$this->_ipad = 1;
223
}
224
}
225
226
227
/* =====================================================
228
* ROBOT (VEREINFACHT & REALISTISCH)
229
* ===================================================== */
230
protected
function
checkForRobot
() {
231
232
$ua = strtolower($this->_agent);
233
234
if
(!$ua)
return
;
235
236
if
(strpos($ua,
'bot'
) !==
false
||
237
strpos($ua,
'crawl'
) !==
false
||
238
strpos($ua,
'spider'
) !==
false
||
239
strpos($ua,
'slurp'
) !==
false
||
240
strpos($ua,
'google'
) !==
false
) {
241
242
$this->_robot = 1;
243
}
244
245
if
($this->_is_robot) {
246
$this->_robot = 1;
247
}
248
}
249
250
251
protected
function
checkForSize
() {
252
if
(isset($_COOKIE[
"dbx_win_size"
])) {
253
$size = explode(
"X"
, $_COOKIE[
"dbx_win_size"
]);
254
if
(isset($size[0])) $this->_width = (int)$size[0];
255
if
(isset($size[1])) $this->_height = (int)$size[1];
256
}
257
}
258
259
260
/* =====================================================
261
* BROWSER (STOP BEIM ERSTEN TREFFER)
262
* ===================================================== */
263
protected
function
checkBrowsers
() {
264
265
if
($this->
checkBrowserGoogleBot
())
return
1;
266
if
($this->
checkBrowserSlurp
())
return
1;
267
if
($this->
checkBrowserInternetExplorer
())
return
1;
268
269
if
($this->
checkBrowserFirefox
())
return
1;
270
271
// Chrome vor Safari!
272
if
($this->
checkBrowserChrome
())
return
1;
273
if
($this->
checkBrowserAndroid
())
return
1;
274
if
($this->
checkBrowserSafari
())
return
1;
275
276
if
($this->
checkBrowserOpera
())
return
1;
277
278
if
($this->
checkBrowseriPhone
())
return
1;
279
if
($this->
checkBrowseriPod
())
return
1;
280
if
($this->
checkBrowserBlackBerry
())
return
1;
281
282
if
($this->
checkBrowserMozilla
())
return
1;
283
284
return
0;
285
}
286
287
288
protected
function
checkBrowserGoogleBot
() {
289
if
(preg_match(
'/googlebot/i'
,$this->_agent)) {
290
$this->_name =
"GOOGLEBOT"
;
291
$this->_is_robot = 1;
292
return
1;
293
}
294
return
0;
295
}
296
297
298
protected
function
checkBrowserSlurp
() {
299
if
(preg_match(
'/slurp/i'
,$this->_agent)) {
300
$this->_name =
"SLURP"
;
301
$this->_is_robot = 1;
302
return
1;
303
}
304
return
0;
305
}
306
307
308
protected
function
checkBrowserInternetExplorer
() {
309
if
(preg_match(
'/msie|trident/i'
,$this->_agent)) {
310
$this->_name =
"IE"
;
311
return
1;
312
}
313
return
0;
314
}
315
316
317
protected
function
checkBrowserFirefox
() {
318
if
(preg_match(
'/firefox/i'
,$this->_agent)) {
319
$this->_name =
"FIREFOX"
;
320
return
1;
321
}
322
return
0;
323
}
324
325
326
protected
function
checkBrowserChrome
() {
327
if
(preg_match(
'/chrome/i'
,$this->_agent) && !preg_match(
'/edg|opr/i'
,$this->_agent)) {
328
$this->_name =
"CHROME"
;
329
return
1;
330
}
331
return
0;
332
}
333
334
335
protected
function
checkBrowserSafari
() {
336
if
(preg_match(
'/safari/i'
,$this->_agent) && !preg_match(
'/chrome/i'
,$this->_agent)) {
337
$this->_name =
"SAFARI"
;
338
return
1;
339
}
340
return
0;
341
}
342
343
344
protected
function
checkBrowserOpera
() {
345
if
(preg_match(
'/opera|opr/i'
,$this->_agent)) {
346
$this->_name =
"OPERA"
;
347
return
1;
348
}
349
return
0;
350
}
351
352
353
protected
function
checkBrowserAndroid
() {
354
if
(preg_match(
'/android/i'
,$this->_agent)) {
355
$this->_name =
"ANDROID"
;
356
$this->_mobile = 1;
357
return
1;
358
}
359
return
0;
360
}
361
362
363
protected
function
checkBrowseriPhone
() {
364
if
(preg_match(
'/iphone/i'
,$this->_agent)) {
365
$this->_name =
"IPHONE"
;
366
$this->_mobile = 1;
367
return
1;
368
}
369
return
0;
370
}
371
372
373
protected
function
checkBrowseriPod
() {
374
if
(preg_match(
'/ipod/i'
,$this->_agent)) {
375
$this->_name =
"IPOD"
;
376
$this->_mobile = 1;
377
return
1;
378
}
379
return
0;
380
}
381
382
383
protected
function
checkBrowserBlackBerry
() {
384
if
(preg_match(
'/blackberry/i'
,$this->_agent)) {
385
$this->_name =
"BLACKBERRY"
;
386
$this->_mobile = 1;
387
return
1;
388
}
389
return
0;
390
}
391
392
393
protected
function
checkBrowserMozilla
() {
394
if
(preg_match(
'/mozilla/i'
,$this->_agent)) {
395
$this->_name =
"MOZILLA"
;
396
return
1;
397
}
398
return
0;
399
}
400
401
402
protected
function
checkPlatform
() {
403
404
if
(preg_match(
'/iphone/i'
, $this->_agent)) $this->_platform =
"IPHONE"
;
405
elseif (preg_match(
'/ipad/i'
, $this->_agent)) $this->_platform =
"IPAD"
;
406
elseif (preg_match(
'/android/i'
, $this->_agent)) $this->_platform =
"ANDROID"
;
407
elseif (preg_match(
'/win/i'
, $this->_agent)) $this->_platform =
"WINDOWS"
;
408
elseif (preg_match(
'/mac/i'
, $this->_agent)) $this->_platform =
"APPLE"
;
409
elseif (preg_match(
'/linux/i'
, $this->_agent)) $this->_platform =
"LINUX"
;
410
411
return
$this->_platform
;
412
}
413
}
dbxBrowser
Definition
dbxBrowser.class.php:3
dbxBrowser\checkBrowserOpera
checkBrowserOpera()
Definition
dbxBrowser.class.php:344
dbxBrowser\checkBrowserFirefox
checkBrowserFirefox()
Definition
dbxBrowser.class.php:317
dbxBrowser\$_width
$_width
Definition
dbxBrowser.class.php:14
dbxBrowser\$_platform
$_platform
Definition
dbxBrowser.class.php:9
dbxBrowser\$_agent
$_agent
Definition
dbxBrowser.class.php:5
dbxBrowser\$_mobile
$_mobile
Definition
dbxBrowser.class.php:11
dbxBrowser\init
init()
Definition
dbxBrowser.class.php:26
dbxBrowser\checkBrowserGoogleBot
checkBrowserGoogleBot()
Definition
dbxBrowser.class.php:288
dbxBrowser\get_ip
get_ip()
Definition
dbxBrowser.class.php:144
dbxBrowser\setVersion
setVersion($version)
Definition
dbxBrowser.class.php:51
dbxBrowser\$_version
$_version
Definition
dbxBrowser.class.php:8
dbxBrowser\$_language
$_language
Definition
dbxBrowser.class.php:6
dbxBrowser\checkBrowserInternetExplorer
checkBrowserInternetExplorer()
Definition
dbxBrowser.class.php:308
dbxBrowser\normalize_ip
normalize_ip($ip)
Definition
dbxBrowser.class.php:169
dbxBrowser\get_host
get_host($ip)
Definition
dbxBrowser.class.php:199
dbxBrowser\__construct
__construct()
Definition
dbxBrowser.class.php:42
dbxBrowser\checkForSize
checkForSize()
Definition
dbxBrowser.class.php:251
dbxBrowser\checkBrowserAndroid
checkBrowserAndroid()
Definition
dbxBrowser.class.php:353
dbxBrowser\$_name
$_name
Definition
dbxBrowser.class.php:7
dbxBrowser\checkPlatform
checkPlatform()
Definition
dbxBrowser.class.php:402
dbxBrowser\checkBrowserSlurp
checkBrowserSlurp()
Definition
dbxBrowser.class.php:298
dbxBrowser\checkForRobot
checkForRobot()
Definition
dbxBrowser.class.php:230
dbxBrowser\$_device
$_device
Definition
dbxBrowser.class.php:4
dbxBrowser\isBrowser
isBrowser($browserName)
Definition
dbxBrowser.class.php:47
dbxBrowser\$_host
$_host
Definition
dbxBrowser.class.php:21
dbxBrowser\checkBrowseriPhone
checkBrowseriPhone()
Definition
dbxBrowser.class.php:363
dbxBrowser\$_java
$_java
Definition
dbxBrowser.class.php:19
dbxBrowser\$_ip
$_ip
Definition
dbxBrowser.class.php:22
dbxBrowser\checkBrowserMozilla
checkBrowserMozilla()
Definition
dbxBrowser.class.php:393
dbxBrowser\$_height
$_height
Definition
dbxBrowser.class.php:15
dbxBrowser\checkBrowserBlackBerry
checkBrowserBlackBerry()
Definition
dbxBrowser.class.php:383
dbxBrowser\checkLanguage
checkLanguage()
Definition
dbxBrowser.class.php:213
dbxBrowser\$_cookie
$_cookie
Definition
dbxBrowser.class.php:16
dbxBrowser\setPlatform
setPlatform($os)
Definition
dbxBrowser.class.php:55
dbxBrowser\checkForIntPad
checkForIntPad()
Definition
dbxBrowser.class.php:220
dbxBrowser\checkBrowserSafari
checkBrowserSafari()
Definition
dbxBrowser.class.php:335
dbxBrowser\$_robot
$_robot
Definition
dbxBrowser.class.php:13
dbxBrowser\$_aol
$_aol
Definition
dbxBrowser.class.php:10
dbxBrowser\$_js
$_js
Definition
dbxBrowser.class.php:18
dbxBrowser\checkBrowseriPod
checkBrowseriPod()
Definition
dbxBrowser.class.php:373
dbxBrowser\$_ipad
$_ipad
Definition
dbxBrowser.class.php:12
dbxBrowser\checkBrowsers
checkBrowsers()
Definition
dbxBrowser.class.php:263
dbxBrowser\$_iframe
$_iframe
Definition
dbxBrowser.class.php:17
dbxBrowser\checkBrowserChrome
checkBrowserChrome()
Definition
dbxBrowser.class.php:326
dbxBrowser\checkMobile
checkMobile()
Definition
dbxBrowser.class.php:63
dbxBrowser\$_flasch
$_flasch
Definition
dbxBrowser.class.php:20
dbx
DBX schema administration.
$_SERVER
$_SERVER['REQUEST_URI']
Definition
run_context_help_provision.php:4
dbx
include
dbxBrowser.class.php
Generated by
1.17.0