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
17 // returns true if User Agent seems to be Netscape brand, false if not
19 // returns true if User Agent seems to be Netscape Communicator 4.x, false if not
21 // returns true if User Agent seems to be a version of Internet Exploder, false if not
22 // function geckobased()
23 // returns true if User Agent seems to be a Gecko-based browser, false if not
24 // function geckodate()
25 // returns the Gecko date when it's a Gecko-based browser, 0 if not
26 // function khtmlbased()
27 // returns true if User Agent seems to be a KHTML-based browser, false if not
29 // collection of some known User Agent Strings:
30 // Mozilla/5.0 (compatible; Konqueror/3; Linux 2.4.18; X11; i686)
31 // Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.3b) Gecko/20030114
32 // Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt)
33 // Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)
34 // Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
35 // Mozilla/4.75 [de] (Win98; U)
36 // Opera/5.12 (Windows 2000; U) [de]
37 // Mozilla/5.0 (Windows; U; Win 9x 4.90; de-DE; m18) Gecko/20010131 Netscape6/6.01
38 // Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.0.1) Gecko/20020823 Netscape/7.0
39 // Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/51 (like Gecko) Safari/51
40 // Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6g
41 // Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20021109 Chimera/0.6+
42 // Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.3a) Gecko/20021207 Phoenix/0.5
43 // Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20021204
44 // Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.05 [ja]
45 // Mozilla/4.0 (compatible; MSIE 5.12; Mac_PowerPC) OmniWeb/4.1.1-v424.6
51 function userAgent($ua_string = "") {
52 // *** constructor ***
53 if (strlen($ua_string)) {
54 $this->uastring = $ua_string;
58 $this->uastring = $_SERVER["HTTP_USER_AGENT"];
61 // get UA brand and version
62 $this->brand = "Unknown"; $this->version = 0;
63 if (ereg("([0-9a-zA-Z\.]+)/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
64 $this->brand = $regs[1]; // this is a reasonable default :)
65 $this->version = $regs[2]; // this is a reasonable default :)
67 if (ereg("Netscape6/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
68 $this->brand = "Netscape";
69 $this->version = $regs[1];
71 elseif (ereg("Netscape/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
72 $this->brand = "Netscape";
73 $this->version = $regs[1];
75 elseif (ereg("Chimera/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
76 $this->brand = "Chimera";
77 $this->version = $regs[1];
79 elseif (ereg("Phoenix/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
80 $this->brand = "Phoenix";
81 $this->version = $regs[1];
83 elseif (ereg("Galeon/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
84 $this->brand = "Galeon";
85 $this->version = $regs[1];
87 elseif (ereg("rv:([0-9a-zA-Z\.+]+)", $this->uastring, $regs) && strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
88 $this->brand = "Mozilla";
89 $this->version = $regs[1];
91 elseif (ereg("Opera[ /]([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
92 $this->brand = "Opera";
93 $this->version = $regs[1];
95 elseif (ereg("OmniWeb/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
96 $this->brand = "OmniWeb";
97 $this->version = $regs[1];
99 elseif (ereg("Konqueror/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
100 $this->brand = "Konqueror";
101 $this->version = $regs[1];
103 elseif (ereg("Safari/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
104 $this->brand = "Safari";
105 $this->version = $regs[1];
107 elseif (ereg("AppleWebKit/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
108 $this->brand = "AppleWebKit";
109 $this->version = $regs[1];
111 elseif (ereg("MSIE ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
112 $this->brand = "Microsoft Internet Explorer";
113 $this->version = $regs[1];
115 elseif (ereg("Mozilla/([0-9a-zA-Z\.+]+)", $this->uastring, $regs) && !strstr($this->uastring, "compatible;") && !strstr($this->uastring, "Gecko/")) {
116 $this->brand = "Netscape";
117 $this->version = $regs[1];
118 if (intval($this->version) == 4) { $this->brand .= " Communicator"; }
123 // set it static so that we don't have to call it that often
125 if (!isset($is_ns)) {
127 if (strstr($this->brand, "Netscape")) {
135 // set it static so that we don't have to call it that often
137 if (!isset($is_ns4)) {
139 if (strstr($this->brand, "Netscape") && (intval($this->version) == 4)) {
147 // set it static so that we don't have to call it that often
149 if (!isset($is_ie)) {
151 if (strstr($this->brand, "Internet Explorer")) {
158 function geckobased() {
159 // set it static so that we don't have to call it that often
161 if (!isset($is_gecko)) {
163 if (strstr($this->uastring, "Gecko/")) {
170 function geckodate() {
171 // set it static so that we don't have to call it that often
173 if (!isset($gdate)) {
175 if (ereg("Gecko/([0-9]+)", $this->uastring, $regs)) {
182 function khtmlbased() {
183 // set it static so that we don't have to call it that often
185 if (!isset($is_khtml)) {
187 if (strstr($this->brand, "Konqueror") || strstr($this->brand, "Safari") || strstr($this->brand, "AppleWebKit")) {