uastring = $ua_string; } else { // read raw UA string $this->uastring = $_SERVER["HTTP_USER_AGENT"]; } // get UA brand and version $this->brand = "Unknown"; $this->version = 0; if (ereg("([0-9a-zA-Z\.]+)/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = $regs[1]; // this is a reasonable default :) $this->version = $regs[2]; // this is a reasonable default :) } if (ereg("Netscape6/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "Netscape"; $this->version = $regs[1]; } elseif (ereg("Netscape/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "Netscape"; $this->version = $regs[1]; } elseif (ereg("Chimera/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "Chimera"; $this->version = $regs[1]; } elseif (ereg("Phoenix/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "Phoenix"; $this->version = $regs[1]; } elseif (ereg("Mozilla Firebird/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "Mozilla Firebird"; $this->version = $regs[1]; } elseif (ereg("Galeon/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "Galeon"; $this->version = $regs[1]; } elseif (ereg("rv:([0-9a-zA-Z\.+]+)", $this->uastring, $regs) && strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) { $this->brand = "Mozilla"; $this->version = $regs[1]; } elseif (ereg("Opera[ /]([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "Opera"; $this->version = $regs[1]; } elseif (ereg("OmniWeb/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "OmniWeb"; $this->version = $regs[1]; } elseif (ereg("Konqueror/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "Konqueror"; $this->version = $regs[1]; } elseif (ereg("Safari/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "Safari"; $this->version = $regs[1]; } elseif (ereg("AppleWebKit/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "AppleWebKit"; $this->version = $regs[1]; } elseif (ereg("MSIE ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) { $this->brand = "Microsoft Internet Explorer"; $this->version = $regs[1]; } elseif (ereg("Mozilla/([0-9a-zA-Z\.+]+)", $this->uastring, $regs) && !strstr($this->uastring, "compatible;") && !strstr($this->uastring, "Gecko/")) { $this->brand = "Netscape"; $this->version = $regs[1]; if (intval($this->version) == 4) { $this->brand .= " Communicator"; } } } function getBrand() { return $this->brand; } function getVersion() { return $this->version; } function isns() { // set it static so that we don't have to call it that often static $is_ns; if (!isset($is_ns)) { $is_ns = false; if (strstr($this->brand, "Netscape")) { $is_ns = true; } } return $is_ns; } function isns4() { // set it static so that we don't have to call it that often static $is_ns4; if (!isset($is_ns4)) { $is_ns4 = false; if (strstr($this->brand, "Netscape") && (intval($this->version) == 4)) { $is_ns4 = true; } } return $is_ns4; } function isie() { // set it static so that we don't have to call it that often static $is_ie; if (!isset($is_ie)) { $is_ie = false; if (strstr($this->brand, "Internet Explorer")) { $is_ie = true; } } return $is_ie; } function geckobased() { // set it static so that we don't have to call it that often static $is_gecko; if (!isset($is_gecko)) { $is_gecko = false; if (strstr($this->uastring, "Gecko/")) { $is_gecko = true; } } return $is_gecko; } function geckodate() { // set it static so that we don't have to call it that often static $gdate; if (!isset($gdate)) { $gdate = 0; if (ereg("Gecko/([0-9]+)", $this->uastring, $regs)) { $gdate = $regs[1]; } } return $gdate; } function khtmlbased() { // set it static so that we don't have to call it that often static $is_khtml; if (!isset($is_khtml)) { $is_khtml = false; if (strstr($this->brand, "Konqueror") || strstr($this->brand, "Safari") || strstr($this->brand, "AppleWebKit")) { $is_khtml = true; } } return $is_khtml; } } ?>