4 // get user agent and tell us what Browser is accessing
6 // function userAgent()
7 // CONSTRUCTOR; reads 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
27 // debug: var $uastring = "Mozilla/5.0 (compatible; Konqueror/3; Linux 2.4.18; X11; i686)";
32 function userAgent() {
33 // *** constructor ***
35 $this->uastring = $_SERVER["HTTP_USER_AGENT"];
37 // get UA brand and version
38 $this->brand = "Unknown"; $this->version = 0;
39 if (ereg("([0-9a-zA-Z\.]+)/([0-9a-zA-Z\.]+)", $this->uastring, $regs)) {
40 $this->uabrand = $regs[1]; // this is a reasonable default :)
41 $this->version = $regs[2]; // this is a reasonable default :)
43 if (ereg("Mozilla/([0-9a-zA-Z\.]+)", $this->uastring, $regs) && !strstr($this->uastring, "compatible;") && !strstr($this->uastring, "Gecko/")) {
44 $this->brand = "Netscape";
45 $this->version = $regs[1];
46 if (intval($this->version) == 4) { $this->brand .= " Communicator"; }
48 elseif (ereg("Netscape6/([0-9a-zA-Z\.]+)", $this->uastring, $regs)) {
49 $this->brand = "Netscape";
50 $this->version = $regs[1];
52 elseif (ereg("Netscape/([0-9a-zA-Z\.]+)", $this->uastring, $regs)) {
53 $this->brand = "Netscape";
54 $this->version = $regs[1];
56 elseif (ereg("rv:([0-9a-zA-Z\.]+)", $this->uastring, $regs) && strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
57 $this->brand = "Mozilla";
58 $this->version = $regs[1];
60 elseif (ereg("Opera[ /]([0-9a-zA-Z\.]+)", $this->uastring, $regs)) {
61 $this->brand = "Opera";
62 $this->version = $regs[1];
64 elseif (ereg("Konqueror/([0-9a-zA-Z\.]+)", $this->uastring, $regs)) {
65 $this->brand = "Konqueror";
66 $this->version = $regs[1];
68 elseif (ereg("MSIE ([0-9a-zA-Z\.]+)", $this->uastring, $regs)) {
69 $this->brand = "Microsoft Internet Explorer";
70 $this->version = $regs[1];
75 // set it static so that we don't have to call it that often
79 if (strstr($this->brand, "Netscape")) {
87 // set it static so that we don't have to call it that often
89 if (!isset($is_ns4)) {
91 if (strstr($this->brand, "Netscape") && (intval($this->version) == 4)) {
99 // set it static so that we don't have to call it that often
101 if (!isset($is_ie)) {
103 if (strstr($this->brand, "Internet Explorer")) {
110 function geckobased() {
111 // set it static so that we don't have to call it that often
113 if (!isset($is_gecko)) {
115 if (strstr($this->uastring, "Gecko/")) {
122 function geckodate() {
123 // set it static so that we don't have to call it that often
125 if (!isset($gdate)) {
127 if (ereg("Gecko/([0-9]+)", $this->uastring, $regs)) {