Passed
Push — 1.10.x ( 6b51fa...7f42c3 )
by
unknown
49:18
created

Browser::checkBrowserWebTv()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %
Metric Value
dl 11
loc 11
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
/**
3
 * File: Browser.php
4
 * Author: Chris Schuld (http://chrisschuld.com/)
5
 * Last Modified: August 20th, 2010
6
 * @version 1.9
7
 * @package PegasusPHP
8
 *
9
 * Copyright (C) 2008-2010 Chris Schuld  ([email protected])
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License as
13
 * published by the Free Software Foundation; either version 2 of
14
 * the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details at:
20
 * http://www.gnu.org/copyleft/gpl.html
21
 *
22
 *
23
 * Typical Usage:
24
 *
25
 *   $browser = new Browser();
26
 *   if( $browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 2 ) {
27
 *    echo 'You have FireFox version 2 or greater';
28
 *   }
29
 *
30
 * User Agents Sampled from: http://www.useragentstring.com/
31
 *
32
 * This implementation is based on the original work from Gary White
33
 * http://apptools.com/phptools/browser/
34
 * Git and Packagist info: https://github.com/cbschuld/Browser.php
35
 */
36
37
class Browser
38
{
39
    private $_agent = '';
40
    private $_browser_name = '';
41
    private $_version = '';
42
    private $_platform = '';
43
    private $_os = '';
44
    private $_is_aol = false;
45
    private $_is_mobile = false;
46
    private $_is_tablet = false;
47
    private $_is_robot = false;
48
    private $_is_facebook = false;
49
    private $_aol_version = '';
50
51
    const BROWSER_UNKNOWN = 'unknown';
52
    const VERSION_UNKNOWN = 'unknown';
53
54
    const BROWSER_OPERA = 'Opera'; // http://www.opera.com/
55
    const BROWSER_OPERA_MINI = 'Opera Mini'; // http://www.opera.com/mini/
56
    const BROWSER_WEBTV = 'WebTV'; // http://www.webtv.net/pc/
57
    const BROWSER_IE = 'Internet Explorer'; // http://www.microsoft.com/ie/
58
    const BROWSER_POCKET_IE = 'Pocket Internet Explorer'; // http://en.wikipedia.org/wiki/Internet_Explorer_Mobile
59
    const BROWSER_KONQUEROR = 'Konqueror'; // http://www.konqueror.org/
60
    const BROWSER_ICAB = 'iCab'; // http://www.icab.de/
61
    const BROWSER_OMNIWEB = 'OmniWeb'; // http://www.omnigroup.com/applications/omniweb/
62
    const BROWSER_FIREBIRD = 'Firebird'; // http://www.ibphoenix.com/
63
    const BROWSER_FIREFOX = 'Firefox'; // http://www.mozilla.com/en-US/firefox/firefox.html
64
    const BROWSER_ICEWEASEL = 'Iceweasel'; // http://www.geticeweasel.org/
65
    const BROWSER_SHIRETOKO = 'Shiretoko'; // http://wiki.mozilla.org/Projects/shiretoko
66
    const BROWSER_MOZILLA = 'Mozilla'; // http://www.mozilla.com/en-US/
67
    const BROWSER_AMAYA = 'Amaya'; // http://www.w3.org/Amaya/
68
    const BROWSER_LYNX = 'Lynx'; // http://en.wikipedia.org/wiki/Lynx
69
    const BROWSER_SAFARI = 'Safari'; // http://apple.com
70
    const BROWSER_IPHONE = 'iPhone'; // http://apple.com
71
    const BROWSER_IPOD = 'iPod'; // http://apple.com
72
    const BROWSER_IPAD = 'iPad'; // http://apple.com
73
    const BROWSER_CHROME = 'Chrome'; // http://www.google.com/chrome
74
    const BROWSER_ANDROID = 'Android'; // http://www.android.com/
75
    const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
76
    const BROWSER_SLURP = 'Yahoo! Slurp'; // http://en.wikipedia.org/wiki/Yahoo!_Slurp
77
    const BROWSER_W3CVALIDATOR = 'W3C Validator'; // http://validator.w3.org/
78
    const BROWSER_BLACKBERRY = 'BlackBerry'; // http://www.blackberry.com/
79
    const BROWSER_ICECAT = 'IceCat'; // http://en.wikipedia.org/wiki/GNU_IceCat
80
    const BROWSER_NOKIA_S60 = 'Nokia S60 OSS Browser'; // http://en.wikipedia.org/wiki/Web_Browser_for_S60
81
    const BROWSER_NOKIA = 'Nokia Browser'; // * all other WAP-based browsers on the Nokia Platform
82
    const BROWSER_MSN = 'MSN Browser'; // http://explorer.msn.com/
83
    const BROWSER_MSNBOT = 'MSN Bot'; // http://search.msn.com/msnbot.htm
84
    const BROWSER_BINGBOT = 'Bing Bot'; // http://en.wikipedia.org/wiki/Bingbot
85
86
    const BROWSER_NETSCAPE_NAVIGATOR = 'Netscape Navigator'; // http://browser.netscape.com/ (DEPRECATED)
87
    const BROWSER_GALEON = 'Galeon'; // http://galeon.sourceforge.net/ (DEPRECATED)
88
    const BROWSER_NETPOSITIVE = 'NetPositive'; // http://en.wikipedia.org/wiki/NetPositive (DEPRECATED)
89
    const BROWSER_PHOENIX = 'Phoenix'; // http://en.wikipedia.org/wiki/History_of_Mozilla_Firefox (DEPRECATED)
90
91
    const PLATFORM_UNKNOWN = 'unknown';
92
    const PLATFORM_WINDOWS = 'Windows';
93
    const PLATFORM_WINDOWS_CE = 'Windows CE';
94
    const PLATFORM_APPLE = 'Apple';
95
    const PLATFORM_LINUX = 'Linux';
96
    const PLATFORM_OS2 = 'OS/2';
97
    const PLATFORM_BEOS = 'BeOS';
98
    const PLATFORM_IPHONE = 'iPhone';
99
    const PLATFORM_IPOD = 'iPod';
100
    const PLATFORM_IPAD = 'iPad';
101
    const PLATFORM_BLACKBERRY = 'BlackBerry';
102
    const PLATFORM_NOKIA = 'Nokia';
103
    const PLATFORM_FREEBSD = 'FreeBSD';
104
    const PLATFORM_OPENBSD = 'OpenBSD';
105
    const PLATFORM_NETBSD = 'NetBSD';
106
    const PLATFORM_SUNOS = 'SunOS';
107
    const PLATFORM_OPENSOLARIS = 'OpenSolaris';
108
    const PLATFORM_ANDROID = 'Android';
109
110
    const OPERATING_SYSTEM_UNKNOWN = 'unknown';
111
112
    public function __construct($userAgent = "")
113
    {
114
        $this->reset();
115
        if ($userAgent != "") {
116
            $this->setUserAgent($userAgent);
117
        } else {
118
            $this->determine();
119
        }
120
    }
121
122
    /**
123
     * Reset all properties
124
     */
125
    public function reset()
126
    {
127
        $this->_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
128
        $this->_browser_name = self::BROWSER_UNKNOWN;
129
        $this->_version = self::VERSION_UNKNOWN;
130
        $this->_platform = self::PLATFORM_UNKNOWN;
131
        $this->_os = self::OPERATING_SYSTEM_UNKNOWN;
132
        $this->_is_aol = false;
133
        $this->_is_mobile = false;
134
        $this->_is_tablet = false;
135
        $this->_is_robot = false;
136
        $this->_is_facebook = false;
137
        $this->_aol_version = self::VERSION_UNKNOWN;
138
    }
139
140
    /**
141
     * Check to see if the specific browser is valid
142
     * @param string $browserName
143
     * @return bool True if the browser is the specified browser
144
     */
145
    function isBrowser($browserName)
146
    {
147
        return (0 == strcasecmp($this->_browser_name, trim($browserName)));
148
    }
149
150
    /**
151
     * The name of the browser.  All return types are from the class contants
152
     * @return string Name of the browser
153
     */
154
    public function getBrowser()
155
    {
156
        return $this->_browser_name;
157
    }
158
159
    /**
160
     * Set the name of the browser
161
     * @param $browser string The name of the Browser
162
     */
163
    public function setBrowser($browser)
164
    {
165
        $this->_browser_name = $browser;
166
    }
167
168
    /**
169
     * The name of the platform.  All return types are from the class contants
170
     * @return string Name of the browser
171
     */
172
    public function getPlatform()
173
    {
174
        return $this->_platform;
175
    }
176
177
    /**
178
     * Set the name of the platform
179
     * @param string $platform The name of the Platform
180
     */
181
    public function setPlatform($platform)
182
    {
183
        $this->_platform = $platform;
184
    }
185
186
    /**
187
     * The version of the browser.
188
     * @return string Version of the browser (will only contain alpha-numeric characters and a period)
189
     */
190
    public function getVersion()
191
    {
192
        return $this->_version;
193
    }
194
195
    /**
196
     * Set the version of the browser
197
     * @param string $version The version of the Browser
198
     */
199
    public function setVersion($version)
200
    {
201
        $this->_version = preg_replace('/[^0-9,.,a-z,A-Z-]/', '', $version);
202
    }
203
204
    /**
205
     * The version of AOL.
206
     * @return string Version of AOL (will only contain alpha-numeric characters and a period)
207
     */
208
    public function getAolVersion()
209
    {
210
        return $this->_aol_version;
211
    }
212
213
    /**
214
     * Set the version of AOL
215
     * @param string $version The version of AOL
216
     */
217
    public function setAolVersion($version)
218
    {
219
        $this->_aol_version = preg_replace('/[^0-9,.,a-z,A-Z]/', '', $version);
220
    }
221
222
    /**
223
     * Is the browser from AOL?
224
     * @return boolean True if the browser is from AOL otherwise false
225
     */
226
    public function isAol()
227
    {
228
        return $this->_is_aol;
229
    }
230
231
    /**
232
     * Is the browser from a mobile device?
233
     * @return boolean True if the browser is from a mobile device otherwise false
234
     */
235
    public function isMobile()
236
    {
237
        return $this->_is_mobile;
238
    }
239
240
    /**
241
     * Is the browser from a tablet device?
242
     * @return boolean True if the browser is from a tablet device otherwise false
243
     */
244
    public function isTablet()
245
    {
246
        return $this->_is_tablet;
247
    }
248
249
    /**
250
     * Is the browser from a robot (ex Slurp,GoogleBot)?
251
     * @return boolean True if the browser is from a robot otherwise false
252
     */
253
    public function isRobot()
254
    {
255
        return $this->_is_robot;
256
    }
257
258
    /**
259
    * Is the browser from facebook?
260
    * @return boolean True if the browser is from facebook otherwise false
261
    */
262
    public function isFacebook()
263
    {
264
        return $this->_is_facebook;
265
    }
266
267
    /**
268
     * Set the browser to be from AOL
269
     * @param $isAol
270
     */
271
    public function setAol($isAol)
272
    {
273
        $this->_is_aol = $isAol;
274
    }
275
276
    /**
277
     * Set the Browser to be mobile
278
     * @param boolean $value is the browser a mobile browser or not
279
     */
280
    protected function setMobile($value = true)
281
    {
282
        $this->_is_mobile = $value;
283
    }
284
285
    /**
286
     * Set the Browser to be tablet
287
     * @param boolean $value is the browser a tablet browser or not
288
     */
289
    protected function setTablet($value = true)
290
    {
291
        $this->_is_tablet = $value;
292
    }
293
294
    /**
295
     * Set the Browser to be a robot
296
     * @param boolean $value is the browser a robot or not
297
     */
298
    protected function setRobot($value = true)
299
    {
300
        $this->_is_robot = $value;
301
    }
302
303
    /**
304
     * Set the Browser to be a Facebook request
305
     * @param boolean $value is the browser a robot or not
306
     */
307
    protected function setFacebook($value = true)
308
    {
309
        $this->_is_facebook = $value;
310
    }
311
312
    /**
313
     * Get the user agent value in use to determine the browser
314
     * @return string The user agent from the HTTP header
315
     */
316
    public function getUserAgent()
317
    {
318
        return $this->_agent;
319
    }
320
321
    /**
322
     * Set the user agent value (the construction will use the HTTP header value - this will overwrite it)
323
     * @param string $agent_string The value for the User Agent
324
     */
325
    public function setUserAgent($agent_string)
326
    {
327
        $this->reset();
328
        $this->_agent = $agent_string;
329
        $this->determine();
330
    }
331
332
    /**
333
     * Used to determine if the browser is actually "chromeframe"
334
     * @since 1.7
335
     * @return boolean True if the browser is using chromeframe
336
     */
337
    public function isChromeFrame()
338
    {
339
        return (strpos($this->_agent, "chromeframe") !== false);
340
    }
341
342
    /**
343
     * Returns a formatted string with a summary of the details of the browser.
344
     * @return string formatted string with a summary of the browser
345
     */
346
    public function __toString()
347
    {
348
        return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" .
349
        "<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" .
350
        "<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" .
351
        "<strong>Platform:</strong> {$this->getPlatform()}<br/>";
352
    }
353
354
    /**
355
     * Protected routine to calculate and determine what the browser is in use (including platform)
356
     */
357
    protected function determine()
358
    {
359
        $this->checkPlatform();
360
        $this->checkBrowsers();
361
        $this->checkForAol();
362
    }
363
364
    /**
365
     * Protected routine to determine the browser type
366
     * @return boolean True if the browser was detected otherwise false
367
     */
368
    protected function checkBrowsers()
369
    {
370
        return (
371
            // well-known, well-used
372
            // Special Notes:
373
            // (1) Opera must be checked before FireFox due to the odd
374
            //     user agents used in some older versions of Opera
375
            // (2) WebTV is strapped onto Internet Explorer so we must
376
            //     check for WebTV before IE
377
            // (3) (deprecated) Galeon is based on Firefox and needs to be
378
            //     tested before Firefox is tested
379
            // (4) OmniWeb is based on Safari so OmniWeb check must occur
380
            //     before Safari
381
            // (5) Netscape 9+ is based on Firefox so Netscape checks
382
            //     before FireFox are necessary
383
            $this->checkBrowserWebTv() ||
384
            $this->checkBrowserInternetExplorer() ||
385
            $this->checkBrowserOpera() ||
386
            $this->checkBrowserGaleon() ||
387
            $this->checkBrowserNetscapeNavigator9Plus() ||
388
            $this->checkBrowserFirefox() ||
389
            $this->checkBrowserChrome() ||
390
            $this->checkBrowserOmniWeb() ||
391
392
            // common mobile
393
            $this->checkBrowserAndroid() ||
394
            $this->checkBrowseriPad() ||
395
            $this->checkBrowseriPod() ||
396
            $this->checkBrowseriPhone() ||
397
            $this->checkBrowserBlackBerry() ||
398
            $this->checkBrowserNokia() ||
399
400
            // common bots
401
            $this->checkBrowserGoogleBot() ||
402
            $this->checkBrowserMSNBot() ||
403
            $this->checkBrowserBingBot() ||
404
            $this->checkBrowserSlurp() ||
405
406
            // check for facebook external hit when loading URL
407
            $this->checkFacebookExternalHit() ||
408
409
            // WebKit base check (post mobile and others)
410
            $this->checkBrowserSafari() ||
411
412
            // everyone else
413
            $this->checkBrowserNetPositive() ||
414
            $this->checkBrowserFirebird() ||
415
            $this->checkBrowserKonqueror() ||
416
            $this->checkBrowserIcab() ||
417
            $this->checkBrowserPhoenix() ||
418
            $this->checkBrowserAmaya() ||
419
            $this->checkBrowserLynx() ||
420
            $this->checkBrowserShiretoko() ||
421
            $this->checkBrowserIceCat() ||
422
            $this->checkBrowserIceweasel() ||
423
            $this->checkBrowserW3CValidator() ||
424
            $this->checkBrowserMozilla() /* Mozilla is such an open standard that you must check it last */
425
        );
426
    }
427
428
    /**
429
     * Determine if the user is using a BlackBerry (last updated 1.7)
430
     * @return boolean True if the browser is the BlackBerry browser otherwise false
431
     */
432
    protected function checkBrowserBlackBerry()
433
    {
434
        if (stripos($this->_agent, 'blackberry') !== false) {
435
            $aresult = explode("/", stristr($this->_agent, "BlackBerry"));
436
            $aversion = explode(' ', $aresult[1]);
437
            $this->setVersion($aversion[0]);
438
            $this->_browser_name = self::BROWSER_BLACKBERRY;
439
            $this->setMobile(true);
440
            return true;
441
        }
442
        return false;
443
    }
444
445
    /**
446
     * Determine if the user is using an AOL User Agent (last updated 1.7)
447
     * @return boolean True if the browser is from AOL otherwise false
448
     */
449
    protected function checkForAol()
450
    {
451
        $this->setAol(false);
452
        $this->setAolVersion(self::VERSION_UNKNOWN);
453
454
        if (stripos($this->_agent, 'aol') !== false) {
455
            $aversion = explode(' ', stristr($this->_agent, 'AOL'));
456
            $this->setAol(true);
457
            $this->setAolVersion(preg_replace('/[^0-9\.a-z]/i', '', $aversion[1]));
458
            return true;
459
        }
460
        return false;
461
    }
462
463
    /**
464
     * Determine if the browser is the GoogleBot or not (last updated 1.7)
465
     * @return boolean True if the browser is the GoogletBot otherwise false
466
     */
467
    protected function checkBrowserGoogleBot()
468
    {
469
        if (stripos($this->_agent, 'googlebot') !== false) {
470
            $aresult = explode('/', stristr($this->_agent, 'googlebot'));
471
            $aversion = explode(' ', $aresult[1]);
472
            $this->setVersion(str_replace(';', '', $aversion[0]));
473
            $this->_browser_name = self::BROWSER_GOOGLEBOT;
474
            $this->setRobot(true);
475
            return true;
476
        }
477
        return false;
478
    }
479
480
    /**
481
     * Determine if the browser is the MSNBot or not (last updated 1.9)
482
     * @return boolean True if the browser is the MSNBot otherwise false
483
     */
484
    protected function checkBrowserMSNBot()
485
    {
486
        if (stripos($this->_agent, "msnbot") !== false) {
487
            $aresult = explode("/", stristr($this->_agent, "msnbot"));
488
            $aversion = explode(" ", $aresult[1]);
489
            $this->setVersion(str_replace(";", "", $aversion[0]));
490
            $this->_browser_name = self::BROWSER_MSNBOT;
491
            $this->setRobot(true);
492
            return true;
493
        }
494
        return false;
495
    }
496
497
    /**
498
     * Determine if the browser is the BingBot or not (last updated 1.9)
499
     * @return boolean True if the browser is the BingBot otherwise false
500
     */
501
    protected function checkBrowserBingBot()
502
    {
503
        if (stripos($this->_agent, "bingbot") !== false) {
504
            $aresult = explode("/", stristr($this->_agent, "bingbot"));
505
            $aversion = explode(" ", $aresult[1]);
506
            $this->setVersion(str_replace(";", "", $aversion[0]));
507
            $this->_browser_name = self::BROWSER_BINGBOT;
508
            $this->setRobot(true);
509
            return true;
510
        }
511
        return false;
512
    }
513
514
    /**
515
     * Determine if the browser is the W3C Validator or not (last updated 1.7)
516
     * @return boolean True if the browser is the W3C Validator otherwise false
517
     */
518
    protected function checkBrowserW3CValidator()
519
    {
520
        if (stripos($this->_agent, 'W3C-checklink') !== false) {
521
            $aresult = explode('/', stristr($this->_agent, 'W3C-checklink'));
522
            $aversion = explode(' ', $aresult[1]);
523
            $this->setVersion($aversion[0]);
524
            $this->_browser_name = self::BROWSER_W3CVALIDATOR;
525
            return true;
526
        } else if (stripos($this->_agent, 'W3C_Validator') !== false) {
527
            // Some of the Validator versions do not delineate w/ a slash - add it back in
528
            $ua = str_replace("W3C_Validator ", "W3C_Validator/", $this->_agent);
529
            $aresult = explode('/', stristr($ua, 'W3C_Validator'));
530
            $aversion = explode(' ', $aresult[1]);
531
            $this->setVersion($aversion[0]);
532
            $this->_browser_name = self::BROWSER_W3CVALIDATOR;
533
            return true;
534
        } else if (stripos($this->_agent, 'W3C-mobileOK') !== false) {
535
            $this->_browser_name = self::BROWSER_W3CVALIDATOR;
536
            $this->setMobile(true);
537
            return true;
538
        }
539
        return false;
540
    }
541
542
    /**
543
     * Determine if the browser is the Yahoo! Slurp Robot or not (last updated 1.7)
544
     * @return boolean True if the browser is the Yahoo! Slurp Robot otherwise false
545
     */
546
    protected function checkBrowserSlurp()
547
    {
548
        if (stripos($this->_agent, 'slurp') !== false) {
549
            $aresult = explode('/', stristr($this->_agent, 'Slurp'));
550
            $aversion = explode(' ', $aresult[1]);
551
            $this->setVersion($aversion[0]);
552
            $this->_browser_name = self::BROWSER_SLURP;
553
            $this->setRobot(true);
554
            $this->setMobile(false);
555
            return true;
556
        }
557
        return false;
558
    }
559
560
    /**
561
     * Determine if the browser is Internet Explorer or not (last updated 1.7)
562
     * @return boolean True if the browser is Internet Explorer otherwise false
563
     */
564
    protected function checkBrowserInternetExplorer()
565
    {
566
567
        // Test for v1 - v1.5 IE
568
        if (stripos($this->_agent, 'microsoft internet explorer') !== false) {
569
            $this->setBrowser(self::BROWSER_IE);
570
            $this->setVersion('1.0');
571
            $aresult = stristr($this->_agent, '/');
572
            if (preg_match('/308|425|426|474|0b1/i', $aresult)) {
573
                $this->setVersion('1.5');
574
            }
575
            return true;
576
        } // Test for versions > 1.5
577
        else if (stripos($this->_agent, 'msie') !== false && stripos($this->_agent, 'opera') === false) {
578
            // See if the browser is the odd MSN Explorer
579 View Code Duplication
            if (stripos($this->_agent, 'msnb') !== false) {
580
                $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'MSN'));
581
                $this->setBrowser(self::BROWSER_MSN);
582
                $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
583
                return true;
584
            }
585
            $aresult = explode(' ', stristr(str_replace(';', '; ', $this->_agent), 'msie'));
586
            $this->setBrowser(self::BROWSER_IE);
587
            $this->setVersion(str_replace(array('(', ')', ';'), '', $aresult[1]));
588
            if(stripos($this->_agent, 'IEMobile') !== false) {
589
                $this->setBrowser(self::BROWSER_POCKET_IE);
590
                $this->setMobile(true);
591
            }
592
            return true;
593
        } // Test for versions > IE 10
594
		else if(stripos($this->_agent, 'trident') !== false) {
595
			$this->setBrowser(self::BROWSER_IE);
596
			$result = explode('rv:', $this->_agent);
597
			$this->setVersion(preg_replace('/[^0-9.]+/', '', $result[1]));
598
			$this->_agent = str_replace(array("Mozilla", "Gecko"), "MSIE", $this->_agent);
599
		} // Test for Pocket IE
600
        else if (stripos($this->_agent, 'mspie') !== false || stripos($this->_agent, 'pocket') !== false) {
601
            $aresult = explode(' ', stristr($this->_agent, 'mspie'));
602
            $this->setPlatform(self::PLATFORM_WINDOWS_CE);
603
            $this->setBrowser(self::BROWSER_POCKET_IE);
604
            $this->setMobile(true);
605
606
            if (stripos($this->_agent, 'mspie') !== false) {
607
                $this->setVersion($aresult[1]);
608
            } else {
609
                $aversion = explode('/', $this->_agent);
610
                $this->setVersion($aversion[1]);
611
            }
612
            return true;
613
        }
614
        return false;
615
    }
616
617
    /**
618
     * Determine if the browser is Opera or not (last updated 1.7)
619
     * @return boolean True if the browser is Opera otherwise false
620
     */
621
    protected function checkBrowserOpera()
622
    {
623
        if (stripos($this->_agent, 'opera mini') !== false) {
624
            $resultant = stristr($this->_agent, 'opera mini');
625
            if (preg_match('/\//', $resultant)) {
626
                $aresult = explode('/', $resultant);
627
                $aversion = explode(' ', $aresult[1]);
628
                $this->setVersion($aversion[0]);
629
            } else {
630
                $aversion = explode(' ', stristr($resultant, 'opera mini'));
631
                $this->setVersion($aversion[1]);
632
            }
633
            $this->_browser_name = self::BROWSER_OPERA_MINI;
634
            $this->setMobile(true);
635
            return true;
636
        } else if (stripos($this->_agent, 'opera') !== false) {
637
            $resultant = stristr($this->_agent, 'opera');
638
            if (preg_match('/Version\/(1*.*)$/', $resultant, $matches)) {
639
                $this->setVersion($matches[1]);
640
            } else if (preg_match('/\//', $resultant)) {
641
                $aresult = explode('/', str_replace("(", " ", $resultant));
642
                $aversion = explode(' ', $aresult[1]);
643
                $this->setVersion($aversion[0]);
644
            } else {
645
                $aversion = explode(' ', stristr($resultant, 'opera'));
646
                $this->setVersion(isset($aversion[1]) ? $aversion[1] : "");
647
            }
648
            if (stripos($this->_agent, 'Opera Mobi') !== false) {
649
                $this->setMobile(true);
650
            }
651
            $this->_browser_name = self::BROWSER_OPERA;
652
            return true;
653
        } else if (stripos($this->_agent, 'OPR') !== false) {
654
            $resultant = stristr($this->_agent, 'OPR');
655
            if (preg_match('/\//', $resultant)) {
656
                $aresult = explode('/', str_replace("(", " ", $resultant));
657
                $aversion = explode(' ', $aresult[1]);
658
                $this->setVersion($aversion[0]);
659
            }
660
            if (stripos($this->_agent, 'Mobile') !== false) {
661
                $this->setMobile(true);
662
            }
663
            $this->_browser_name = self::BROWSER_OPERA;
664
            return true;
665
        }
666
        return false;
667
    }
668
669
    /**
670
     * Determine if the browser is Chrome or not (last updated 1.7)
671
     * @return boolean True if the browser is Chrome otherwise false
672
     */
673
    protected function checkBrowserChrome()
674
    {
675
        if (stripos($this->_agent, 'Chrome') !== false) {
676
            $aresult = explode('/', stristr($this->_agent, 'Chrome'));
677
            $aversion = explode(' ', $aresult[1]);
678
            $this->setVersion($aversion[0]);
679
            $this->setBrowser(self::BROWSER_CHROME);
680
            //Chrome on Android
681 View Code Duplication
            if (stripos($this->_agent, 'Android') !== false) {
682
                if (stripos($this->_agent, 'Mobile') !== false) {
683
                    $this->setMobile(true);
684
                } else {
685
                    $this->setTablet(true);
686
                }
687
            }
688
            return true;
689
        }
690
        return false;
691
    }
692
693
694
    /**
695
     * Determine if the browser is WebTv or not (last updated 1.7)
696
     * @return boolean True if the browser is WebTv otherwise false
697
     */
698 View Code Duplication
    protected function checkBrowserWebTv()
699
    {
700
        if (stripos($this->_agent, 'webtv') !== false) {
701
            $aresult = explode('/', stristr($this->_agent, 'webtv'));
702
            $aversion = explode(' ', $aresult[1]);
703
            $this->setVersion($aversion[0]);
704
            $this->setBrowser(self::BROWSER_WEBTV);
705
            return true;
706
        }
707
        return false;
708
    }
709
710
    /**
711
     * Determine if the browser is NetPositive or not (last updated 1.7)
712
     * @return boolean True if the browser is NetPositive otherwise false
713
     */
714
    protected function checkBrowserNetPositive()
715
    {
716 View Code Duplication
        if (stripos($this->_agent, 'NetPositive') !== false) {
717
            $aresult = explode('/', stristr($this->_agent, 'NetPositive'));
718
            $aversion = explode(' ', $aresult[1]);
719
            $this->setVersion(str_replace(array('(', ')', ';'), '', $aversion[0]));
720
            $this->setBrowser(self::BROWSER_NETPOSITIVE);
721
            return true;
722
        }
723
        return false;
724
    }
725
726
    /**
727
     * Determine if the browser is Galeon or not (last updated 1.7)
728
     * @return boolean True if the browser is Galeon otherwise false
729
     */
730 View Code Duplication
    protected function checkBrowserGaleon()
731
    {
732
        if (stripos($this->_agent, 'galeon') !== false) {
733
            $aresult = explode(' ', stristr($this->_agent, 'galeon'));
734
            $aversion = explode('/', $aresult[0]);
735
            $this->setVersion($aversion[1]);
736
            $this->setBrowser(self::BROWSER_GALEON);
737
            return true;
738
        }
739
        return false;
740
    }
741
742
    /**
743
     * Determine if the browser is Konqueror or not (last updated 1.7)
744
     * @return boolean True if the browser is Konqueror otherwise false
745
     */
746 View Code Duplication
    protected function checkBrowserKonqueror()
747
    {
748
        if (stripos($this->_agent, 'Konqueror') !== false) {
749
            $aresult = explode(' ', stristr($this->_agent, 'Konqueror'));
750
            $aversion = explode('/', $aresult[0]);
751
            $this->setVersion($aversion[1]);
752
            $this->setBrowser(self::BROWSER_KONQUEROR);
753
            return true;
754
        }
755
        return false;
756
    }
757
758
    /**
759
     * Determine if the browser is iCab or not (last updated 1.7)
760
     * @return boolean True if the browser is iCab otherwise false
761
     */
762
    protected function checkBrowserIcab()
763
    {
764
        if (stripos($this->_agent, 'icab') !== false) {
765
            $aversion = explode(' ', stristr(str_replace('/', ' ', $this->_agent), 'icab'));
766
            $this->setVersion($aversion[1]);
767
            $this->setBrowser(self::BROWSER_ICAB);
768
            return true;
769
        }
770
        return false;
771
    }
772
773
    /**
774
     * Determine if the browser is OmniWeb or not (last updated 1.7)
775
     * @return boolean True if the browser is OmniWeb otherwise false
776
     */
777 View Code Duplication
    protected function checkBrowserOmniWeb()
778
    {
779
        if (stripos($this->_agent, 'omniweb') !== false) {
780
            $aresult = explode('/', stristr($this->_agent, 'omniweb'));
781
            $aversion = explode(' ', isset($aresult[1]) ? $aresult[1] : "");
782
            $this->setVersion($aversion[0]);
783
            $this->setBrowser(self::BROWSER_OMNIWEB);
784
            return true;
785
        }
786
        return false;
787
    }
788
789
    /**
790
     * Determine if the browser is Phoenix or not (last updated 1.7)
791
     * @return boolean True if the browser is Phoenix otherwise false
792
     */
793 View Code Duplication
    protected function checkBrowserPhoenix()
794
    {
795
        if (stripos($this->_agent, 'Phoenix') !== false) {
796
            $aversion = explode('/', stristr($this->_agent, 'Phoenix'));
797
            $this->setVersion($aversion[1]);
798
            $this->setBrowser(self::BROWSER_PHOENIX);
799
            return true;
800
        }
801
        return false;
802
    }
803
804
    /**
805
     * Determine if the browser is Firebird or not (last updated 1.7)
806
     * @return boolean True if the browser is Firebird otherwise false
807
     */
808 View Code Duplication
    protected function checkBrowserFirebird()
809
    {
810
        if (stripos($this->_agent, 'Firebird') !== false) {
811
            $aversion = explode('/', stristr($this->_agent, 'Firebird'));
812
            $this->setVersion($aversion[1]);
813
            $this->setBrowser(self::BROWSER_FIREBIRD);
814
            return true;
815
        }
816
        return false;
817
    }
818
819
    /**
820
     * Determine if the browser is Netscape Navigator 9+ or not (last updated 1.7)
821
     * NOTE: (http://browser.netscape.com/ - Official support ended on March 1st, 2008)
822
     * @return boolean True if the browser is Netscape Navigator 9+ otherwise false
823
     */
824
    protected function checkBrowserNetscapeNavigator9Plus()
825
    {
826
        if (stripos($this->_agent, 'Firefox') !== false && preg_match('/Navigator\/([^ ]*)/i', $this->_agent, $matches)) {
827
            $this->setVersion($matches[1]);
828
            $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
829
            return true;
830
        } else if (stripos($this->_agent, 'Firefox') === false && preg_match('/Netscape6?\/([^ ]*)/i', $this->_agent, $matches)) {
831
            $this->setVersion($matches[1]);
832
            $this->setBrowser(self::BROWSER_NETSCAPE_NAVIGATOR);
833
            return true;
834
        }
835
        return false;
836
    }
837
838
    /**
839
     * Determine if the browser is Shiretoko or not (https://wiki.mozilla.org/Projects/shiretoko) (last updated 1.7)
840
     * @return boolean True if the browser is Shiretoko otherwise false
841
     */
842 View Code Duplication
    protected function checkBrowserShiretoko()
843
    {
844
        if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/Shiretoko\/([^ ]*)/i', $this->_agent, $matches)) {
845
            $this->setVersion($matches[1]);
846
            $this->setBrowser(self::BROWSER_SHIRETOKO);
847
            return true;
848
        }
849
        return false;
850
    }
851
852
    /**
853
     * Determine if the browser is Ice Cat or not (http://en.wikipedia.org/wiki/GNU_IceCat) (last updated 1.7)
854
     * @return boolean True if the browser is Ice Cat otherwise false
855
     */
856 View Code Duplication
    protected function checkBrowserIceCat()
857
    {
858
        if (stripos($this->_agent, 'Mozilla') !== false && preg_match('/IceCat\/([^ ]*)/i', $this->_agent, $matches)) {
859
            $this->setVersion($matches[1]);
860
            $this->setBrowser(self::BROWSER_ICECAT);
861
            return true;
862
        }
863
        return false;
864
    }
865
866
    /**
867
     * Determine if the browser is Nokia or not (last updated 1.7)
868
     * @return boolean True if the browser is Nokia otherwise false
869
     */
870
    protected function checkBrowserNokia()
871
    {
872
        if (preg_match("/Nokia([^\/]+)\/([^ SP]+)/i", $this->_agent, $matches)) {
873
            $this->setVersion($matches[2]);
874
            if (stripos($this->_agent, 'Series60') !== false || strpos($this->_agent, 'S60') !== false) {
875
                $this->setBrowser(self::BROWSER_NOKIA_S60);
876
            } else {
877
                $this->setBrowser(self::BROWSER_NOKIA);
878
            }
879
            $this->setMobile(true);
880
            return true;
881
        }
882
        return false;
883
    }
884
885
    /**
886
     * Determine if the browser is Firefox or not (last updated 1.7)
887
     * @return boolean True if the browser is Firefox otherwise false
888
     */
889
    protected function checkBrowserFirefox()
890
    {
891
        if (stripos($this->_agent, 'safari') === false) {
892
            if (preg_match("/Firefox[\/ \(]([^ ;\)]+)/i", $this->_agent, $matches)) {
893
                $this->setVersion($matches[1]);
894
                $this->setBrowser(self::BROWSER_FIREFOX);
895
                //Firefox on Android
896 View Code Duplication
                if (stripos($this->_agent, 'Android') !== false) {
897
                    if (stripos($this->_agent, 'Mobile') !== false) {
898
                        $this->setMobile(true);
899
                    } else {
900
                        $this->setTablet(true);
901
                    }
902
                }
903
                return true;
904
            } else if (preg_match("/Firefox$/i", $this->_agent, $matches)) {
905
                $this->setVersion("");
906
                $this->setBrowser(self::BROWSER_FIREFOX);
907
                return true;
908
            }
909
        }
910
        return false;
911
    }
912
913
    /**
914
     * Determine if the browser is Firefox or not (last updated 1.7)
915
     * @return boolean True if the browser is Firefox otherwise false
916
     */
917 View Code Duplication
    protected function checkBrowserIceweasel()
918
    {
919
        if (stripos($this->_agent, 'Iceweasel') !== false) {
920
            $aresult = explode('/', stristr($this->_agent, 'Iceweasel'));
921
            $aversion = explode(' ', $aresult[1]);
922
            $this->setVersion($aversion[0]);
923
            $this->setBrowser(self::BROWSER_ICEWEASEL);
924
            return true;
925
        }
926
        return false;
927
    }
928
929
    /**
930
     * Determine if the browser is Mozilla or not (last updated 1.7)
931
     * @return boolean True if the browser is Mozilla otherwise false
932
     */
933
    protected function checkBrowserMozilla()
934
    {
935
        if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) {
936
            $aversion = explode(' ', stristr($this->_agent, 'rv:'));
937
            preg_match('/rv:[0-9].[0-9][a-b]?/i', $this->_agent, $aversion);
938
            $this->setVersion(str_replace('rv:', '', $aversion[0]));
939
            $this->setBrowser(self::BROWSER_MOZILLA);
940
            return true;
941
        } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/rv:[0-9]\.[0-9]/i', $this->_agent) && stripos($this->_agent, 'netscape') === false) {
942
            $aversion = explode('', stristr($this->_agent, 'rv:'));
943
            $this->setVersion(str_replace('rv:', '', $aversion[0]));
944
            $this->setBrowser(self::BROWSER_MOZILLA);
945
            return true;
946
        } else if (stripos($this->_agent, 'mozilla') !== false && preg_match('/mozilla\/([^ ]*)/i', $this->_agent, $matches) && stripos($this->_agent, 'netscape') === false) {
947
            $this->setVersion($matches[1]);
948
            $this->setBrowser(self::BROWSER_MOZILLA);
949
            return true;
950
        }
951
        return false;
952
    }
953
954
    /**
955
     * Determine if the browser is Lynx or not (last updated 1.7)
956
     * @return boolean True if the browser is Lynx otherwise false
957
     */
958 View Code Duplication
    protected function checkBrowserLynx()
959
    {
960
        if (stripos($this->_agent, 'lynx') !== false) {
961
            $aresult = explode('/', stristr($this->_agent, 'Lynx'));
962
            $aversion = explode(' ', (isset($aresult[1]) ? $aresult[1] : ""));
963
            $this->setVersion($aversion[0]);
964
            $this->setBrowser(self::BROWSER_LYNX);
965
            return true;
966
        }
967
        return false;
968
    }
969
970
    /**
971
     * Determine if the browser is Amaya or not (last updated 1.7)
972
     * @return boolean True if the browser is Amaya otherwise false
973
     */
974 View Code Duplication
    protected function checkBrowserAmaya()
975
    {
976
        if (stripos($this->_agent, 'amaya') !== false) {
977
            $aresult = explode('/', stristr($this->_agent, 'Amaya'));
978
            $aversion = explode(' ', $aresult[1]);
979
            $this->setVersion($aversion[0]);
980
            $this->setBrowser(self::BROWSER_AMAYA);
981
            return true;
982
        }
983
        return false;
984
    }
985
986
    /**
987
     * Determine if the browser is Safari or not (last updated 1.7)
988
     * @return boolean True if the browser is Safari otherwise false
989
     */
990
    protected function checkBrowserSafari()
991
    {
992
        if (stripos($this->_agent, 'Safari') !== false
993
            && stripos($this->_agent, 'iPhone') === false
994
            && stripos($this->_agent, 'iPod') === false) {
995
996
            $aresult = explode('/', stristr($this->_agent, 'Version'));
997
            if (isset($aresult[1])) {
998
                $aversion = explode(' ', $aresult[1]);
999
                $this->setVersion($aversion[0]);
1000
            } else {
1001
                $this->setVersion(self::VERSION_UNKNOWN);
1002
            }
1003
            $this->setBrowser(self::BROWSER_SAFARI);
1004
            return true;
1005
        }
1006
        return false;
1007
    }
1008
1009
    /**
1010
     * Detect if URL is loaded from FacebookExternalHit
1011
     * @return boolean True if it detects FacebookExternalHit otherwise false
1012
     */
1013
    protected function checkFacebookExternalHit()
1014
    {
1015
        if(stristr($this->_agent,'FacebookExternalHit'))
1016
        {
1017
            $this->setRobot(true);
1018
            $this->setFacebook(true);
1019
            return true;
1020
        }
1021
        return false;
1022
    }
1023
1024
    /**
1025
     * Detect if URL is being loaded from internal Facebook browser
1026
     * @return boolean True if it detects internal Facebook browser otherwise false
1027
     */
1028
    protected function checkForFacebookIos()
1029
    {
1030
        if(stristr($this->_agent,'FBIOS'))
1031
        {
1032
            $this->setFacebook(true);
1033
            return true;
1034
        }
1035
        return false;
1036
    }
1037
1038
    /**
1039
     * Detect Version for the Safari browser on iOS devices
1040
     * @return boolean True if it detects the version correctly otherwise false
1041
     */
1042 View Code Duplication
    protected function getSafariVersionOnIos()
1043
    {
1044
        $aresult = explode('/',stristr($this->_agent,'Version'));
1045
        if( isset($aresult[1]) )
1046
        {
1047
            $aversion = explode(' ',$aresult[1]);
1048
            $this->setVersion($aversion[0]);
1049
            return true;
1050
        }
1051
        return false;
1052
    }
1053
1054
    /**
1055
     * Detect Version for the Chrome browser on iOS devices
1056
     * @return boolean True if it detects the version correctly otherwise false
1057
     */
1058 View Code Duplication
    protected function getChromeVersionOnIos()
1059
    {
1060
        $aresult = explode('/',stristr($this->_agent,'CriOS'));
1061
        if( isset($aresult[1]) )
1062
        {
1063
            $aversion = explode(' ',$aresult[1]);
1064
            $this->setVersion($aversion[0]);
1065
            $this->setBrowser(self::BROWSER_CHROME);
1066
            return true;
1067
        }
1068
        return false;
1069
    }
1070
1071
    /**
1072
     * Determine if the browser is iPhone or not (last updated 1.7)
1073
     * @return boolean True if the browser is iPhone otherwise false
1074
     */
1075 View Code Duplication
    protected function checkBrowseriPhone() {
1076
        if( stripos($this->_agent,'iPhone') !== false ) {
1077
            $this->setVersion(self::VERSION_UNKNOWN);
1078
            $this->setBrowser(self::BROWSER_IPHONE);
1079
            $this->getSafariVersionOnIos();
1080
            $this->getChromeVersionOnIos();
1081
            $this->checkForFacebookIos();
1082
            $this->setMobile(true);
1083
            return true;
1084
        }
1085
        return false;
1086
    }
1087
1088
    /**
1089
     * Determine if the browser is iPad or not (last updated 1.7)
1090
     * @return boolean True if the browser is iPad otherwise false
1091
     */
1092 View Code Duplication
    protected function checkBrowseriPad() {
1093
        if( stripos($this->_agent,'iPad') !== false ) {
1094
            $this->setVersion(self::VERSION_UNKNOWN);
1095
            $this->setBrowser(self::BROWSER_IPAD);
1096
            $this->getSafariVersionOnIos();
1097
            $this->getChromeVersionOnIos();
1098
            $this->checkForFacebookIos();
1099
            $this->setTablet(true);
1100
            return true;
1101
        }
1102
        return false;
1103
    }
1104
1105
    /**
1106
     * Determine if the browser is iPod or not (last updated 1.7)
1107
     * @return boolean True if the browser is iPod otherwise false
1108
     */
1109 View Code Duplication
    protected function checkBrowseriPod() {
1110
        if( stripos($this->_agent,'iPod') !== false ) {
1111
            $this->setVersion(self::VERSION_UNKNOWN);
1112
            $this->setBrowser(self::BROWSER_IPOD);
1113
            $this->getSafariVersionOnIos();
1114
            $this->getChromeVersionOnIos();
1115
            $this->checkForFacebookIos();
1116
            $this->setMobile(true);
1117
            return true;
1118
        }
1119
        return false;
1120
    }
1121
1122
    /**
1123
     * Determine if the browser is Android or not (last updated 1.7)
1124
     * @return boolean True if the browser is Android otherwise false
1125
     */
1126
    protected function checkBrowserAndroid()
1127
    {
1128
        if (stripos($this->_agent, 'Android') !== false) {
1129
            $aresult = explode(' ', stristr($this->_agent, 'Android'));
1130
            if (isset($aresult[1])) {
1131
                $aversion = explode(' ', $aresult[1]);
1132
                $this->setVersion($aversion[0]);
1133
            } else {
1134
                $this->setVersion(self::VERSION_UNKNOWN);
1135
            }
1136
            if (stripos($this->_agent, 'Mobile') !== false) {
1137
                $this->setMobile(true);
1138
            } else {
1139
                $this->setTablet(true);
1140
            }
1141
            $this->setBrowser(self::BROWSER_ANDROID);
1142
            return true;
1143
        }
1144
        return false;
1145
    }
1146
1147
    /**
1148
     * Determine the user's platform (last updated 1.7)
1149
     */
1150
    protected function checkPlatform()
1151
    {
1152
        if (stripos($this->_agent, 'windows') !== false)
1153
        {
1154
            $this->_platform = self::PLATFORM_WINDOWS;
1155
        }
1156
        else if (stripos($this->_agent, 'iPad') !== false)
1157
        {
1158
            $this->_platform = self::PLATFORM_IPAD;
1159
        }
1160
        else if (stripos($this->_agent, 'iPod') !== false)
1161
        {
1162
            $this->_platform = self::PLATFORM_IPOD;
1163
        }
1164
        else if (stripos($this->_agent, 'iPhone') !== false)
1165
        {
1166
            $this->_platform = self::PLATFORM_IPHONE;
1167
        }
1168
        elseif (stripos($this->_agent, 'mac') !== false)
1169
        {
1170
            $this->_platform = self::PLATFORM_APPLE;
1171
        }
1172
        elseif (stripos($this->_agent, 'android') !== false)
1173
        {
1174
            $this->_platform = self::PLATFORM_ANDROID;
1175
        }
1176
        elseif (stripos($this->_agent, 'linux') !== false)
1177
        {
1178
            $this->_platform = self::PLATFORM_LINUX;
1179
        }
1180
        else if (stripos($this->_agent, 'Nokia') !== false)
1181
        {
1182
            $this->_platform = self::PLATFORM_NOKIA;
1183
        }
1184
        else if (stripos($this->_agent, 'BlackBerry') !== false)
1185
        {
1186
            $this->_platform = self::PLATFORM_BLACKBERRY;
1187
        }
1188
        elseif (stripos($this->_agent, 'FreeBSD') !== false)
1189
        {
1190
            $this->_platform = self::PLATFORM_FREEBSD;
1191
        }
1192
        elseif (stripos($this->_agent, 'OpenBSD') !== false)
1193
        {
1194
            $this->_platform = self::PLATFORM_OPENBSD;
1195
        }
1196
        elseif (stripos($this->_agent, 'NetBSD') !== false)
1197
        {
1198
            $this->_platform = self::PLATFORM_NETBSD;
1199
        }
1200
        elseif (stripos($this->_agent, 'OpenSolaris') !== false)
1201
        {
1202
            $this->_platform = self::PLATFORM_OPENSOLARIS;
1203
        }
1204
        elseif (stripos($this->_agent, 'SunOS') !== false)
1205
        {
1206
            $this->_platform = self::PLATFORM_SUNOS;
1207
        }
1208
        elseif (stripos($this->_agent, 'OS\/2') !== false)
1209
        {
1210
            $this->_platform = self::PLATFORM_OS2;
1211
        }
1212
        elseif (stripos($this->_agent, 'BeOS') !== false)
1213
        {
1214
            $this->_platform = self::PLATFORM_BEOS;
1215
        }
1216
        elseif (stripos($this->_agent, 'win') !== false)
1217
        {
1218
            $this->_platform = self::PLATFORM_WINDOWS;
1219
        }
1220
1221
    }
1222
}
1223
1224
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
1225