Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Client {
- const VERSION = 1;
- const AUTHOR = 'Sidney Liebrand';
- public static $Browser = null;
- public static $System = null;
- public static $Execution = null;
- private static $Compatibility = 0;
- private static $browsers = array(
- 'Opera' => array(
- 'name' => '/(OPR)|(Opera)/i',
- 'alts' => '',
- 'version' => '/(\sOPR\/([0-9\.]+))|(\sVersion\/([0-9\.]+))|(\sOpera\/([0-9\.]+))|(\sOpera\s([0-9\.]+))/i',
- 'engine' => array(
- 'name' => '/(\sGecko)|((\s|)Presto)|(\sAppleWebKit)/i',
- 'version' => '/(\sAppleWebKit\/([0-9\.]+)\s)|(\srv:([0-9\.]+))|((\s|)Presto\/([0-9\.]+)\s)/i'
- )
- ),
- 'Msie' => array(
- 'name' => '/MSIE/i',
- 'alts' => '',
- 'version' => '/(\s|)MSIE\s([0-9\.b]+)/',
- 'engine' => array(
- 'name' => '!Trident',
- 'version' => '/\sTrident\/([0-9\.]+)(;|\s|)/i'
- )
- ),
- 'Maxthon' => array(
- 'name' => '/Maxthon/i',
- 'alts' => '',
- 'version' => '/\sMaxthon(\/|[\s]{1})([0-9\.]+)/i',
- 'engine' => array(
- 'name' => '/(\sGecko)|(\sPresto)|(\sAppleWebKit)|(Trident)/i',
- 'version' => '/(\sTrident\/([0-9\.]+))|(\sAppleWebKit\/([0-9\.]+))/i'
- )
- ),
- 'Firefox' => array(
- 'name' => '/Firefox|Iceweasel|Firebird|IceCat|Netscape|SeaMonkey|Conkeror|Kazehakase/i',
- 'alts' => '/\sIceweasel|Firebird|IceCat|Netscape|SeaMonkey|Conkeror|Kazehakase/i',
- 'version' => '/\sFirefox\/([0-9\.]+)|Iceweasel\/([0-9\.]+)|Firebird\/([0-9\.]+)|IceCat\/([0-9\.]+)|Netscape\/([0-9\.]+)|SeaMonkey(\/[0-9\.]+)|Conkeror(\/[0-9\.]+)|Kazehakase(\/[0-9\.]+)/i',
- 'engine' => array(
- 'name' => '!Gecko',
- 'version' => '/\srv:([0-9\.]+)/i'
- )
- ),
- 'Konqueror' => array(
- 'name' => '/Konqueror/',
- 'alts' => '',
- 'version' => '/Konqueror\/([0-9\.]+)/',
- 'engine' => array(
- 'name' => '!Gecko',
- 'version' => '/KHTML\/([0-9\.]+)/i'
- )
- ),
- 'Rockmelt' => array(
- 'name' => '/RockMelt/i',
- 'alts' => '',
- 'version' => '/\sRockMelt\/([0-9\.]+)/i',
- 'engine' => array(
- 'name' => '!Webkit',
- 'version' => '/\sAppleWebKit\/([0-9\.]+)/i'
- )
- ),
- 'Chrome' => array(
- 'name' => '/Chrome|Comodo/i',
- 'alts' => '',
- 'version' => '/\sChrome\/([0-9\.]+)/i',
- 'engine' => array(
- 'name' => '!Webkit',
- 'version' => '/\sAppleWebKit\/([0-9\.]+)/i'
- )
- ),
- 'Safari' => array(
- 'name' => '/Safari/i',
- 'alts' => '',
- 'version' => '/\sVersion\/([0-9\.]+)/i',
- 'engine' => array(
- 'name' => '!Webkit',
- 'version' => '/\sAppleWebKit\/([0-9\.]+)/i'
- )
- )
- );
- public static function init() {
- static::$Execution = new Stdclass;
- static::$Execution->Time = new Stdclass();
- static::$Execution->Memory = new Stdclass();
- static::setExecutionStart();
- static::$Browser = new Stdclass;
- static::$Browser->Engine = new Stdclass;
- static::$Browser->Encoding = new Stdclass;
- static::$Browser->Cookies = new Stdclass;
- static::$System = new Stdclass;
- static::getUserAgent();
- static::getInfo();
- static::setExecutionEnd();
- static::setExecutionVars();
- }
- private function __construct() {}
- private function __clone() {}
- private static function getUserAgent($userAgent = null) {
- $pattern = '/Mozilla\/[0-9\.]+(\s|)/';
- if ($userAgent === null || strlen($userAgent) === 0)
- $userAgent = $_SERVER['HTTP_USER_AGENT'];
- static::$Browser->UserAgent = preg_replace($pattern, '', $userAgent);
- }
- private static function getInfo() {
- static::setCompatibility();
- static::getBrowserName();
- if (static::$Browser->Name) {
- static::getAltBrowserName();
- static::getBrowserVersion();
- static::getEngineName();
- static::getEngineVersion();
- static::getBrowserEncoding();
- static::getBrowserLanguage();
- static::getCookiesEnabled();
- static::getClientSystem();
- static::getMobile();
- static::getHTMLClasses();
- }
- }
- private static function setExecutionVars() {
- static::$Execution->Time->Total = (static::$Execution->Time->End - static::$Execution->Time->Start);
- static::$Execution->Memory->Total = (static::$Execution->Memory->End - static::$Execution->Memory->Start);
- }
- private static function setExecutionStart() {
- static::$Execution->Time->Start = microtime(true);
- static::$Execution->Memory->Start = memory_get_usage();
- }
- private static function setExecutionEnd() {
- static::$Execution->Time->End = microtime(true);
- static::$Execution->Memory->End = memory_get_usage();
- }
- private static function setCompatibility() {
- static::$Compatibility = preg_match('/compatible(;|)/i', static::$Browser->UserAgent) ? 1 : 0;
- }
- private static function getMobile() {
- static::$System->Mobile = 0;
- if (preg_match('/(Mobile)|(Phone)|(Android)|(iPhone)|(Windows\sPhone)/i', static::$Browser->UserAgent))
- static::$System->Mobile = 1;
- }
- private static function getBrowserName() {
- $detected = false;
- while ($detected === false && list($name, $pattern) = each(static::$browsers))
- if (preg_match($pattern['name'], static::$Browser->UserAgent))
- $detected = true;
- static::$Browser->Name = ucfirst(strtolower(($detected) ? $name : null));
- }
- private static function getAltBrowserName() {
- $pattern = strlen(static::$browsers[static::$Browser->Name]['alts']) > 0 ? static::$browsers[static::$Browser->Name]['alts'] : null;
- if ($pattern === null) {
- static::$Browser->AltName = null;
- return false;
- }
- preg_match($pattern, static::$Browser->UserAgent, $altArr);
- static::$Browser->AltName = isset($altArr[0]) ? $altArr[0] : null;
- }
- private static function getBrowserVersion() {
- $pattern = isset(static::$browsers[static::$Browser->Name]['version']) ? static::$browsers[static::$Browser->Name]['version'] : null;
- if ($pattern === null) {
- static::$Browser->Version = null;
- return null;
- }
- preg_match($pattern, static::$Browser->UserAgent, $version);
- $diff = (static::$Browser->Name === 'Opera');
- $version = static::arrayClean($version);
- static::$Browser->Version = isset($version[($diff ? 2 : 1)]) ? $version[($diff ? 2 : 1)] : (isset($version[0]) ? $version[0] : null);
- static::$Browser->MajorVersion = static::getMajorVersion(static::$Browser->Version);
- }
- private static function getEngineName() {
- $engine = isset(static::$browsers[static::$Browser->Name]['engine']['name']) ? static::$browsers[static::$Browser->Name]['engine']['name'] : null;
- static::$Browser->Engine->Name = null;
- if ($engine === null)
- return null;
- if (static::firstCharIs('!', $engine))
- static::$Browser->Engine->Name = substr($engine, 1);
- else {
- preg_match($engine, static::$Browser->UserAgent, $engArr);
- $ENGINE = isset($engArr[1]) ? static::arrayClean($engArr)[1] : null;
- static::$Browser->Engine->Name = $ENGINE;
- }
- }
- private static function getEngineVersion() {
- $pattern = isset(static::$browsers[static::$Browser->Name]['engine']['version']) ? static::$browsers[static::$Browser->Name]['engine']['version'] : null;
- if (static::$Browser->Name === 'Msie' && static::$Browser->MajorVersion == 7) {
- static::$Browser->Engine->Version = 3.1;
- return true;
- } else if ($pattern === null) {
- static::$Browser->Engine->Version = null;
- return null;
- }
- preg_match($pattern, static::$Browser->UserAgent, $engineVersion);
- $diff = (static::$Browser->Name === 'Opera' || static::$Browser->Name === 'Maxthon');
- static::$Browser->Engine->Version = isset($engineVersion[($diff ? 2 : 1)]) ? static::arrayClean($engineVersion)[($diff ? 2 : 1)] : null;
- static::$Browser->Engine->MajorVersion = static::getMajorVersion(static::$Browser->Engine->Version);
- }
- private static function getBrowserLanguage() {
- if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
- static::$Browser->Lang = strtoupper(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
- }
- private static function getBrowserEncoding() {
- static::$Browser->Encoding->Accept = 0;
- static::$Browser->Encoding->Options = null;
- if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
- $mtd = explode(',', str_replace(' ', '', $_SERVER['HTTP_ACCEPT_ENCODING']));
- static::$Browser->Encoding->Accept = 1;
- static::$Browser->Encoding->Options = $mtd;
- }
- }
- private static function getCookiesEnabled() {
- setcookie('cookie', 1, (time()+3600));
- static::$Browser->Cookies->Enabled = 0;
- if (isset($_COOKIE) && count($_COOKIE) > 0)
- static::$Browser->Cookies->Enabled = 1;
- }
- private static function getClientSystem() {
- $ua = static::$Browser->UserAgent;
- if (static::$Compatibility == 1)
- $ua = str_replace('compatible', '', static::$Browser->UserAgent);
- preg_match('/(\s|)([a-zA-Z][a-zA-Z][a-z]+[a-zA-Z]+)(;|(\s|\)))/', $ua, $os);
- static::$System->CPU = static::getClientCpuClass();
- static::$System->IP = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
- static::$System->ID = isset($os[1]) ? static::arrayClean($os)[1] : null;
- static::$System->Port = isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : null;
- }
- private static function getClientCpuClass() {
- $x64 = '/(x64)|(x86_64)|(WOW64)|(Win64)/i';
- if (preg_match($x64, static::$Browser->UserAgent))
- return 64;
- return 32;
- }
- private static function getHTMLClasses() {
- $classStr = '';
- $classStr .= static::$Browser->Name;
- $classStr .= ' '. static::$Browser->Name.static::$Browser->MajorVersion;
- $classStr .= strlen(static::$Browser->AltName) > 0 ? ' '. static::$Browser->AltName : '';
- $classStr .= ' '. static::$Browser->Engine->Name;
- $classStr .= ' '. static::$Browser->Engine->Name.static::$Browser->Engine->MajorVersion;
- $classStr .= static::$System->Mobile == 1 ? ' Mobile' : '';
- if(static::$System->ID) {
- $sysID = static::$System->ID;
- if (preg_match('/(mac|win)/i', $sysID))
- $sysID = substr($sysID, 0, 3);
- $classStr .= ' '. $sysID;
- $classStr .= ' '. $sysID.static::$System->CPU;
- }
- $classStr = implode(' ', array_unique(explode(' ', $classStr)));
- $classStr = preg_replace('/[\s]+/', ' ', $classStr);
- static::$Browser->HTMLClasses = preg_replace('/Unknown[a-z0-9]+\s/i', '', strtolower($classStr));
- }
- private static function getMajorVersion($fullversion) {
- preg_match('/([0-9a-zA-Z]+)/i', $fullversion, $versionArray);
- return isset($versionArray[0]) ? $versionArray[0] : null;
- }
- private static function firstCharIs($char, $string) {
- return (substr($string, 0, 1) === $char) ? true : false;
- }
- private static function arrayClean($array = null) {
- if (!is_array($array))
- return null;
- foreach ($array as $key => $value)
- $array[$key] = str_replace(' ', '', $value);
- $array = array_filter($array);
- $array = array_values($array);
- return $array;
- }
- }
- Client::init();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement