Source for file WebAPI_Browser.php
Documentation is available at WebAPI_Browser.php
* Project: WebAPI_Browser :: Get browser information
* File: WebAPI/WebAPI_Browser.php
* WebAPI_Browser class는 Browser의 정보를 구한다.
* @subpackage WebAPI_Browser
* @author JoungKyun.Kim <http://oops.org>
* @copyright (c) 2018, OOPS.org
* @link http://pear.oops.org/package/WebAPI
* Get browser information
* WebAPI_Browser class는 Browser의 정보를 구한다.
* @param string (optional) User Agent를 강제로 지정할 경우 사용
static public function exec ($u = null) {
$_SERVER['HTTP_USER_AGENT'] = $u;
$ua = &$_SERVER['HTTP_USER_AGENT'];
self::LANGUAGE ($br, $ua);
self::isMobile ($br, $ua);
if ( preg_match ('/Konqueror\/([0-9]+(\.[0-9]+)?)/', $ua, $m) )
if ( preg_match ('/Edge\/([0-9]+(\.[0-9]+)?)/', $ua, $m) ) {
else if ( preg_match ('/Chrome|CriOS|CrMo/', $ua) ) {
if ( preg_match ('/(Chrome|CriOS|CrMo)\/([0-9]+(\.[0-9]+)?)/', $ua, $m) ) {
$br->engine = ($m[2] > 27) ? 'Blink' : 'WebKit';
else if ( preg_match ('/Safari|AppleWebKit/', $ua) ) {
if ( preg_match ('/Safari\/([0-9]+(\.[0-9]+)?)/', $ua, $m) )
if ( preg_match ('/KHTML\/([0-9]+(\.[0-9]+)?)/', $ua, $m) )
$br->name = 'BlackBerry';
$br->engine = 'BlackBerry';
if ( preg_match ('/MSIE ([0-9]+(\.[0-9]+)?)/', $ua, $m) ) {
if ( $br->ostype == 'Mac' && $br->version > 4 )
else if ( $br->version > 3 )
if ( preg_match ('/rv:([0-9]+(\.[0-9]+)?)/', $ua, $m) )
else if ( preg_match ('/Netscape|Mozilla\/[1-4]\.([1-9]|[0-9][1-9])/i', $ua) ) {
$br->engine = 'Netscape';
if ( preg_match ('/Netscape[0-9]?\/([0-9]+(\.[0-9]+)?)/', $ua, $m) ) {
if ( $br->name == 'Mozilla' && preg_match ('/Thunderbird/', $ua) )
$br->name = 'Thunderbird';
if ( preg_match ('/(Firefox|Thunderbird)\/([0-9]+(\.[0-9]+(\.[0-9]+)?)?)/', $ua, $m) )
if ( preg_match ('/rv:([0-9]+(\.[0-9]+(\.[0-9]+)?)?)/', $ua, $m) )
else if ( preg_match ('/(Lynx|w3m|Links)/i', $ua, $m) ) {
if ( preg_match ('/Opera\/([0-9.]+)/', $ua, $m) ) {
if ( $br->version > 6 && $br->version < 15 )
static public function OS (&$v, $ua = null) {
$ua = &$_SERVER['HTTP_USER_AGENT'];
else if ( preg_match ('/RIM Tablet OS ([0-9.]+)/', $ua, $m) ) {
static public function LANGUAGE (&$v, $ua = null) {
$ua = &$_SERVER['HTTP_USER_AGENT'];
if ( ! preg_match ('/([a-z]{2})[-_]([a-zA-Z]{2})/', $ua, $m) ) {
static public function isMobile (&$v, $ua = null) {
$ua = &$_SERVER['HTTP_USER_AGENT'];
if ( ! isset ($v->mobile) )
'/Mobile|iPhone|iPad|Android|BlackBerry| RIM |' .
'Tablet|Fennec|Opera mobi|dows CE|HTC/i';
if ( ! $v->mobile && preg_match ('/Android|iOS|Symbian/i', $ua) )
if ( $v->mobile === true && preg_match ('/Windows/', $v->ostype) )
$v->ostype = 'Windows Mobile';
// {{{ +-- private (void) initVar (&$br)
* @param stdClass 초기화할 stdClass property
static public function initVar () {
// {{{ +-- private WINDOWS (&$v)
private function WINDOWS (&$v, $ua = null) {
$ua = &$_SERVER['HTTP_USER_AGENT'];
# Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko
$v->ostype = 'Windows Mobile';
if ( preg_match ('/Windows Phone (OS )?([0-9.]+)/', $ua, $m) )
$v->os = 'Phone ' . $m[2];
$v->ostype = 'Windows NT';
// {{{ +-- private LINUX (&$v)
private function LINUX (&$v, $ua = null) {
$ua = &$_SERVER['HTTP_USER_AGENT'];
if ( preg_match ('/Android[- ][0-9].[0-9]/', $ua, $m) ) {
} else if ( preg_match ('/Android|J2ME/', $ua, $m) ) {
if ( preg_match ('/Linux ([0-9]+\.[0-9]+)/', $ua, $m) )
// {{{ +-- private MAC (&$v)
private function MAC (&$v, $ua = null) {
$ua = &$_SERVER['HTTP_USER_AGENT'];
// {{{ +-- private BLACKBERRY (&$v)
private function BLACKBERRY (&$v) {
$ua = &$_SERVER['HTTP_USER_AGENT'];
if ( preg_match ('/BlackBerry([0-9]+)\/([0-9]+\.[0-9]+)/', $ua, $m) ) {
$v->os = 'BlackBerry' . $m[2];
$v->ostype = 'BlackBerry';
* vim: set filetype=php noet sw=4 ts=4 fdm=marker:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
|