4 // get user agent and tell us what Browser is accessing
6 // function userAgent([$ua_string])
7 // CONSTRUCTOR; reads UA string (or takes the optional given UA string) and gets info from that into our variables.
10 // the plain User Agent string
12 // returns the User Agent brand name
14 // the User Agent version
16 // function getBrand()
17 // returns the User Agent Brand Name
18 // function getVersion()
19 // returns the User Agent version
22 // returns true if User Agent seems to be Netscape brand, false if not
24 // returns true if User Agent seems to be Netscape Communicator 4.x, false if not
26 // returns true if User Agent seems to be a version of Internet Exploder, false if not
27 // function geckobased()
28 // returns true if User Agent seems to be a Gecko-based browser, false if not
29 // function geckodate()
30 // returns the Gecko date when it's a Gecko-based browser, 0 if not
31 // function khtmlbased()
32 // returns true if User Agent seems to be a KHTML-based browser, false if not
34 // collection of some known User Agent Strings:
35 // Mozilla/5.0 (compatible; Konqueror/3; Linux 2.4.18; X11; i686)
36 // Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.3b) Gecko/20030114
37 // Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt)
38 // Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)
39 // Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
40 // Mozilla/4.75 [de] (Win98; U)
41 // Opera/5.12 (Windows 2000; U) [de]
42 // Mozilla/5.0 (Windows; U; Win 9x 4.90; de-DE; m18) Gecko/20010131 Netscape6/6.01
43 // Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.0.1) Gecko/20020823 Netscape/7.0
44 // Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/51 (like Gecko) Safari/51
45 // Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6g
46 // Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20021109 Chimera/0.6+
47 // Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.3a) Gecko/20021207 Phoenix/0.5
48 // Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20021204
49 // Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.05 [ja]
50 // Mozilla/4.0 (compatible; MSIE 5.12; Mac_PowerPC) OmniWeb/4.1.1-v424.6
51 // Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6
52 // Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.5a) Gecko/20030728 Mozilla Firebird/0.6.1
59 function userAgent($ua_string = "") {
60 // *** constructor ***
61 if (strlen($ua_string)) {
62 $this->uastring = $ua_string;
66 $this->uastring = $_SERVER["HTTP_USER_AGENT"];
69 // get UA brand and version
70 $this->brand = "Unknown"; $this->version = 0;
71 if (ereg("([0-9a-zA-Z\.]+)/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
72 $this->brand = $regs[1]; // this is a reasonable default :)
73 $this->version = $regs[2]; // this is a reasonable default :)
75 if (ereg("Netscape6/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
76 $this->brand = "Netscape";
77 $this->version = $regs[1];
79 elseif (ereg("Netscape/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
80 $this->brand = "Netscape";
81 $this->version = $regs[1];
83 elseif (ereg("Chimera/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
84 $this->brand = "Chimera";
85 $this->version = $regs[1];
87 elseif (ereg("Phoenix/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
88 $this->brand = "Phoenix";
89 $this->version = $regs[1];
91 elseif (ereg("Mozilla Firebird/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
92 $this->brand = "Mozilla Firebird";
93 $this->version = $regs[1];
95 elseif (ereg("Galeon/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
96 $this->brand = "Galeon";
97 $this->version = $regs[1];
99 elseif (ereg("rv:([0-9a-zA-Z\.+]+)", $this->uastring, $regs) && strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
100 $this->brand = "Mozilla";
101 $this->version = $regs[1];
103 elseif (ereg("Opera[ /]([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
104 $this->brand = "Opera";
105 $this->version = $regs[1];
107 elseif (ereg("OmniWeb/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
108 $this->brand = "OmniWeb";
109 $this->version = $regs[1];
111 elseif (ereg("Konqueror/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
112 $this->brand = "Konqueror";
113 $this->version = $regs[1];
115 elseif (ereg("Safari/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
116 $this->brand = "Safari";
117 $this->version = $regs[1];
119 elseif (ereg("AppleWebKit/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
120 $this->brand = "AppleWebKit";
121 $this->version = $regs[1];
123 elseif (ereg("MSIE ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
124 $this->brand = "Microsoft Internet Explorer";
125 $this->version = $regs[1];
127 elseif (ereg("Mozilla/([0-9a-zA-Z\.+]+)", $this->uastring, $regs) && !strstr($this->uastring, "compatible;") && !strstr($this->uastring, "Gecko/")) {
128 $this->brand = "Netscape";
129 $this->version = $regs[1];
130 if (intval($this->version) == 4) { $this->brand .= " Communicator"; }
134 function getBrand() { return $this->brand; }
135 function getVersion() { return $this->version; }
138 // set it static so that we don't have to call it that often
140 if (!isset($is_ns)) {
142 if (strstr($this->brand, "Netscape")) {
150 // set it static so that we don't have to call it that often
152 if (!isset($is_ns4)) {
154 if (strstr($this->brand, "Netscape") && (intval($this->version) == 4)) {
162 // set it static so that we don't have to call it that often
164 if (!isset($is_ie)) {
166 if (strstr($this->brand, "Internet Explorer")) {
173 function geckobased() {
174 // set it static so that we don't have to call it that often
176 if (!isset($is_gecko)) {
178 if (strstr($this->uastring, "Gecko/")) {
185 function geckodate() {
186 // set it static so that we don't have to call it that often
188 if (!isset($gdate)) {
190 if (ereg("Gecko/([0-9]+)", $this->uastring, $regs)) {
197 function khtmlbased() {
198 // set it static so that we don't have to call it that often
200 if (!isset($is_khtml)) {
202 if (strstr($this->brand, "Konqueror") || strstr($this->brand, "Safari") || strstr($this->brand, "AppleWebKit")) {