📄 detect.php
字号:
$os['win2k'] = (strpos($agt, 'windows nt 5.0') !== false); $os['winxp'] = (strpos($agt, 'windows nt 5.1') !== false); $os['win98'] = (strpos($agt, 'win98') !== false) || (strpos($agt, 'windows 98') !== false); $os['win9x'] = $os['win95'] || $os['win98']; $os['winnt'] = ((strpos($agt, 'winnt') !== false) || (strpos($agt, 'windows nt') !== false)) && (strpos($agt, 'windows nt 5') === false); $os['win32'] = $os['win95'] || $os['winnt'] || $os['win98'] || $majorVersion >= 4 && (strpos($agt, 'win32') !== false) || (strpos($agt, '32bit') !== false); $os['os2'] = (strpos($agt, 'os/2') !== false) || (strpos($agt, 'ibm-webexplorer') !== false); $os['mac'] = (strpos($agt, 'mac') !== false); $os['mac68k'] = $os['mac'] && ((strpos($agt, '68k') !== false) || (strpos($agt, '68000') !== false)); $os['macppc'] = $os['mac'] && ((strpos($agt, 'ppc') !== false) || (strpos($agt, 'powerpc') !== false)); $os['sun'] = (strpos($agt, 'sunos') !== false); $os['sun4'] = (strpos($agt, 'sunos 4') !== false); $os['sun5'] = (strpos($agt, 'sunos 5') !== false); $os['suni86'] = $os['sun'] && (strpos($agt, 'i86') !== false); $os['irix'] = (strpos($agt, 'irix') !== false); $os['irix5'] = (strpos($agt, 'irix 5') !== false); $os['irix6'] = (strpos($agt, 'irix 6') !== false) || (strpos($agt, 'irix6') !== false); $os['hpux'] = (strpos($agt, 'hp-ux') !== false); $os['hpux9'] = $os['hpux'] && (strpos($agt, '09.') !== false); $os['hpux10'] = $os['hpux'] && (strpos($agt, '10.') !== false); $os['aix'] = (strpos($agt, 'aix') !== false); $os['aix1'] = (strpos($agt, 'aix 1') !== false); $os['aix2'] = (strpos($agt, 'aix 2') !== false); $os['aix3'] = (strpos($agt, 'aix 3') !== false); $os['aix4'] = (strpos($agt, 'aix 4') !== false); $os['linux'] = (strpos($agt, 'inux') !== false); $os['sco'] = (strpos($agt, 'sco') !== false) || (strpos($agt, 'unix_sv') !== false); $os['unixware'] = (strpos($agt, 'unix_system_v') !== false); $os['mpras'] = (strpos($agt, 'ncr') !== false); $os['reliant'] = (strpos($agt, 'reliant') !== false); $os['dec'] = (strpos($agt, 'dec') !== false) || (strpos($agt, 'osf1') !== false) || (strpos($agt, 'dec_alpha') !== false) || (strpos($agt, 'alphaserver') !== false) || (strpos($agt, 'ultrix') !== false) || (strpos($agt, 'alphastation') !== false); $os['sinix'] = (strpos($agt, 'sinix') !== false); $os['freebsd'] = (strpos($agt, 'freebsd') !== false); $os['bsd'] = (strpos($agt, 'bsd') !== false); $os['unix'] = (strpos($agt, 'x11') !== false) || (strpos($agt, 'unix') !== false) || $os['sun'] || $os['irix'] || $os['hpux'] || $os['sco'] || $os['unixware'] || $os['mpras'] || $os['reliant'] || $os['dec'] || $os['sinix'] || $os['aix'] || $os['linux'] || $os['bsd'] || $os['freebsd']; $os['vms'] = (strpos($agt, 'vax') !== false) || (strpos($agt, 'openvms') !== false); } // Setup the quirks if ($detectFlags[NET_USERAGENT_DETECT_ALL] || ($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_QUIRKS])) { if ($browser['konq']) { Net_UserAgent_Detect::setQuirk('empty_file_input_value'); } if ($browser['ie']) { Net_UserAgent_Detect::setQuirk('cache_ssl_downloads'); } if ($browser['ie6']) { Net_UserAgent_Detect::setQuirk('scrollbar_in_way'); } if ($browser['ie5']) { Net_UserAgent_Detect::setQuirk('break_disposition_header'); } if ($browser['ns6']) { Net_UserAgent_Detect::setQuirk('popups_disabled'); Net_UserAgent_Detect::setQuirk('must_cache_forms'); } if ($browser['nav'] && $subVersion < .79) { Net_UserAgent_Detect::setQuirk('nested_table_render_bug'); } } // Set features if ($detectFlags[NET_USERAGENT_DETECT_ALL] || ($detectFlags[NET_USERAGENT_DETECT_BROWSER] && $detectFlags[NET_USERAGENT_DETECT_FEATURES])) { if ($browser['gecko']) { preg_match(';gecko/([\d]+)\b;i', $agt, $matches); Net_UserAgent_Detect::setFeature('gecko', $matches[1]); } if ($browser['ns6up'] || $browser['opera5up'] || $browser['konq']) { Net_UserAgent_Detect::setFeature('dom'); } if ($browser['ie4up'] || $browser['ns4up'] || $browser['opera5up'] || $browser['konq']) { Net_UserAgent_Detect::setFeature('dhtml'); } } if ($detectFlags[NET_USERAGENT_DETECT_ALL] || $detectFlags[NET_USERAGENT_DETECT_ACCEPT]) { $mimetypes = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT'), 0, strpos(getenv('HTTP_ACCEPT') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); Net_UserAgent_Detect::setAcceptType((array) $mimetypes, 'mimetype'); $languages = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_LANGUAGE'), 0, strpos(getenv('HTTP_ACCEPT_LANGUAGE') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); if (empty($languages)) { $languages = 'en'; } Net_UserAgent_Detect::setAcceptType((array) $languages, 'language'); $encodings = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_ENCODING'), 0, strpos(getenv('HTTP_ACCEPT_ENCODING') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); Net_UserAgent_Detect::setAcceptType((array) $encodings, 'encoding'); $charsets = preg_split(';[\s,]+;', substr(getenv('HTTP_ACCEPT_CHARSET'), 0, strpos(getenv('HTTP_ACCEPT_CHARSET') . ';', ';')), -1, PREG_SPLIT_NO_EMPTY); Net_UserAgent_Detect::setAcceptType((array) $charsets, 'charset'); } } // }}} // {{{ setOption() /** * Sets a class option. The available settings are: * o 'userAgent' => The user agent string to detect (useful for * checking a string manually). * o 'detectOptions' => The level of checking to do. A single level * or an array of options. Default is NET_USERAGENT_DETECT_ALL. * * @param string $in_field The option field (userAgent or detectOptions) * @param mixed $in_value The value for the field */ function setOption($in_field, $in_value) { $options = &Net_UserAgent_Detect::_getStaticProperty('options'); $options[$in_field] = $in_value; } // }}} // {{{ isBrowser() /** * Look up the provide browser flag and return a boolean value * * Given one of the flags listed in the properties, this function will return * the value associated with that flag. * * @param string $in_match flag to lookup * * @access public * @return boolean whether or not the browser satisfies this flag */ function isBrowser($in_match) { Net_UserAgent_Detect::detect(); $browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); return isset($browser[strtolower($in_match)]) ? $browser[strtolower($in_match)] : false; } // }}} // {{{ getBrowser() /** * Since simply returning the "browser" is somewhat ambiguous since there * are different ways to classify the browser, this function works by taking * an expect list and returning the string of the first match, so put the important * ones first in the array. * * @param array $in_expectList the browser flags to search for * * @access public * @return string first flag that matches */ function getBrowser($in_expectList) { Net_UserAgent_Detect::detect(); $browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); foreach((array) $in_expectList as $brwsr) { if (!empty($browser[strtolower($brwsr)])) { return $brwsr; } } } // }}} // {{{ getBrowserString() /** * This function returns the vendor string corresponding to the flag. * * Either use the default matches or pass in an associative array of * flags and corresponding vendor strings. This function will find * the highest version flag and return the vendor string corresponding * to the appropriate flag. Be sure to pass in the flags in ascending order * if you want a basic matches first, followed by more detailed matches. * * @param array $in_vendorStrings (optional) array of flags matched with vendor strings * * @access public * @return string vendor string matches appropriate flag */ function getBrowserString($in_vendorStrings = array ( 'ie' => 'Microsoft Internet Explorer', 'ie4up' => 'Microsoft Internet Explorer 4.x', 'ie5up' => 'Microsoft Internet Explorer 5.x', 'ie6up' => 'Microsoft Internet Explorer 6.x', 'opera4' => 'Opera 4.x', 'opera5up' => 'Opera 5.x', 'nav' => 'Netscape Navigator', 'ns4' => 'Netscape 4.x', 'ns6up' => 'Mozilla/Netscape 6.x', 'konq' => 'Konqueror/Safari', )) { Net_UserAgent_Detect::detect(); $browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); foreach((array) $in_vendorStrings as $flag => $string) { if (!empty($browser[$flag])) { $vendorString = $string; } } // if there are no matches just use the user agent leading idendifier (usually Mozilla) if (!isset($vendorString)) { $leadingIdentifier = &Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier'); $vendorString = $leadingIdentifier; } return $vendorString; } // }}} // {{{ isIE() /** * Determine if the browser is an Internet Explorer browser * * @access public * @return bool whether or not this browser is an ie browser */ function isIE() { Net_UserAgent_Detect::detect(); $browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); return !empty($browser['ie']); } // }}} // {{{ isNavigator() /** * Determine if the browser is a Netscape Navigator browser * * @access public * @return bool whether or not this browser is a Netscape Navigator browser */ function isNavigator() { Net_UserAgent_Detect::detect(); $browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); return !empty($browser['nav']); } // }}} // {{{ isNetscape() /** * Determine if the browser is a Netscape or Mozilla browser * * Note that this function is not the same as isNavigator, since the * new Mozilla browsers are still sponsered by Netscape, and hence are * Netscape products, but not the original Navigators * * @access public * @return bool whether or not this browser is a Netscape product */ function isNetscape() { Net_UserAgent_Detect::detect(); $browser = &Net_UserAgent_Detect::_getStaticProperty('browser'); return !empty($browser['ns4up']); } // }}} // {{{ isOS() /** * Look up the provide OS flag and return a boolean value * * Given one of the flags listed in the properties, this function will return * the value associated with that flag for the operating system. * * @param string $in_match flag to lookup * * @access public * @return boolean whether or not the OS satisfies this flag */ function isOS($in_match) { Net_UserAgent_Detect::detect(); $os = &Net_UserAgent_Detect::_getStaticProperty('os'); return isset($os[strtolower($in_match)]) ? $os[strtolower($in_match)] : false; } // }}} // {{{ getOS() /** * Since simply returning the "os" is somewhat ambiguous since there * are different ways to classify the browser, this function works by taking * an expect list and returning the string of the first match, so put the important * ones first in the array. * * @access public * @return string first flag that matches */ function getOS($in_expectList) { Net_UserAgent_Detect::detect();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -