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 // bool: true if this agent is a bot
18 // array of static user agent data (static vars in functions are set for all objects of this class!)
20 // function getBrand()
21 // returns the User Agent Brand Name
22 // function getVersion()
23 // returns the User Agent version
25 // function getUAString()
26 // returns the full User Agent string
29 // returns true if User Agent seems to be a bot
31 // returns true if User Agent seems to be Netscape brand, false if not
33 // returns true if User Agent seems to be Netscape Communicator 4.x, false if not
35 // returns true if User Agent seems to be a version of Internet Exploder, false if not
36 // function geckobased()
37 // returns true if User Agent seems to be a Gecko-based browser, false if not
38 // function geckodate()
39 // returns the Gecko date when it's a Gecko-based browser, 0 if not
40 // function khtmlbased()
41 // returns true if User Agent seems to be a KHTML-based browser, false if not
43 // collection of some known User Agent Strings:
44 // Mozilla/5.0 (compatible; Konqueror/3; Linux 2.4.18; X11; i686)
45 // Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.3b) Gecko/20030114
46 // Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt)
47 // Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)
48 // Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
49 // Mozilla/4.75 [de] (Win98; U)
50 // Opera/5.12 (Windows 2000; U) [de]
51 // Mozilla/5.0 (Windows; U; Win 9x 4.90; de-DE; m18) Gecko/20010131 Netscape6/6.01
52 // Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.0.1) Gecko/20020823 Netscape/7.0
53 // Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/51 (like Gecko) Safari/51
54 // Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6g
55 // Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20021109 Chimera/0.6+
56 // Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.3a) Gecko/20021207 Phoenix/0.5
57 // Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20021204
58 // Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.05 [ja]
59 // Mozilla/4.0 (compatible; MSIE 5.12; Mac_PowerPC) OmniWeb/4.1.1-v424.6
60 // Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6
61 // Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.5a) Gecko/20030728 Mozilla Firebird/0.6.1
63 // *** search bots: ***
64 // W3C_Validator/1.305.2.12 libwww-perl/5.64
67 // Vagabondo/2.0 MT (webagent at wise-guys dot nl)
68 // TurnitinBot/1.5 ( ">http://www.turnitin.com/robot/crawlerinfo.html)
69 // FAST-WebCrawler/3.x Multimedia (mm dash crawler at fast dot no)
70 // Firefly/1.0 (compatible; Mozilla 4.0; MSIE 5.5)
71 // Googlebot/2.1 (+ ">http://www.googlebot.com/bot.html)
72 // Scrubby/2.2 ( ">http://www.scrubtheweb.com/)
73 // psbot/0.1 (+ ">http://www.picsearch.com/bot.html)
75 // URL_Spider_Pro/3.0 ( ">http://www.innerprise.net/usp-spider.asp)"
76 // Pompos/1.3 ">http://dir.com/pompos.html
77 // Szukacz/1.5 (robot; www.szukacz.pl/jakdzialarobot.html; info@szukacz.pl)
80 // NetResearchServer/2.7(loopimprovements.com/robot.html)
81 // dloader(NaverRobot)/1.0
82 // Mozilla/4.0 compatible ZyBorg/1.0 Daily Refresh Beta-d03 (wn.zyborg@looksmart.net;
83 // Mozilla/2.0 (compatible; Ask Jeeves/Teoma)
84 // Mozilla/5.0 (Slurp/si; slurp@inktomi.com; ">http://www.inktomi.com/slurp.html)
85 // Mozilla/5.0 [en] (compatible; Gulper Web Bot 0.2.4 www.ecsl.cs.sunysb.edu/~maxim/cgi-bin/Link/GulperBot)
86 // Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; Girafabot; girafabot at girafa dot com;
87 // Mozilla/4.0 (efp@gmx.net)
88 // Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)
89 // PingALink Monitoring Services 1.0 (http://www.pingalink.com)
90 // IlTrovatore-Setaccio (+ ">http://www.iltrovatore.it)
92 // appie 1.1 (www.walhello.com)
93 // larbin_2.6.2 (larbin2.6.2@unspecified.mail)
95 // search.ch V1.4.2 (spiderman@search.ch;
96 // WebFilter Robot 1.0
97 // Openfind data gatherer, Openbot/3.0+(robot-response@openfind.com.tw;+
99 // Internet Explorer 5.5
101 // Mozilla/4.0 (compatible; B-l-i-t-z-B-O-T)
102 // B l i t z B O T @ t r i c u s . n e t (Mozilla compatible)
103 // sitecheck.internetseer.com (For more info see: ">http://sitecheck.internetseer.com)
104 // http://www.almaden.ibm.com/cs/crawler [c01]
108 // HeinrichderMiragoRobot
115 var $uadata = array();
117 function userAgent($ua_string = "") {
118 // *** constructor ***
119 if (strlen($ua_string)) {
120 $this->uastring = $ua_string;
123 // read raw UA string
124 $this->uastring = $_SERVER["HTTP_USER_AGENT"];
127 // get UA brand and version
128 $this->brand = "Unknown"; $this->version = 0;
129 if (ereg("([0-9a-zA-Z\.()-]+)/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
130 $this->brand = $regs[1]; // this is a reasonable default :)
131 $this->version = $regs[2]; // this is a reasonable default :)
133 if (ereg("Netscape6/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
134 $this->brand = "Netscape";
135 $this->version = $regs[1];
137 elseif (ereg("Netscape/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
138 $this->brand = "Netscape";
139 $this->version = $regs[1];
141 elseif (ereg("Chimera/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
142 $this->brand = "Chimera";
143 $this->version = $regs[1];
145 elseif (ereg("Phoenix/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
146 $this->brand = "Phoenix";
147 $this->version = $regs[1];
149 elseif (ereg("Mozilla Firebird/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
150 $this->brand = "Mozilla Firebird";
151 $this->version = $regs[1];
153 elseif (ereg("Galeon/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
154 $this->brand = "Galeon";
155 $this->version = $regs[1];
157 elseif (ereg("rv:([0-9a-zA-Z\.+]+)", $this->uastring, $regs) && strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
158 $this->brand = "Mozilla";
159 $this->version = $regs[1];
161 elseif (ereg("Opera[ /]([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
162 $this->brand = "Opera";
163 $this->version = $regs[1];
165 elseif (ereg("OmniWeb/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
166 $this->brand = "OmniWeb";
167 $this->version = $regs[1];
169 elseif (ereg("Konqueror/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
170 $this->brand = "Konqueror";
171 $this->version = $regs[1];
173 elseif (ereg("Safari/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
174 $this->brand = "Safari";
175 $this->version = $regs[1];
177 elseif (ereg("AppleWebKit/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
178 $this->brand = "AppleWebKit";
179 $this->version = $regs[1];
181 elseif (ereg("W3C_Validator/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
182 $this->brand = "W3C_Validator";
183 $this->version = $regs[1];
186 elseif (ereg("ZyBorg/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
187 $this->brand = "ZyBorg";
188 $this->version = $regs[1];
191 elseif (ereg("Ask Jeeves/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
192 $this->brand = "Ask Jeeves";
193 $this->version = $regs[1];
196 elseif (ereg("Slurp/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
197 $this->brand = "Slurp";
198 $this->version = $regs[1];
201 elseif (ereg("Openbot/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
202 $this->brand = "Openbot";
203 $this->version = $regs[1];
206 elseif (ereg("Mercator-([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
207 $this->brand = "Mercator";
208 $this->version = $regs[1];
211 elseif (ereg("appie ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
212 $this->brand = "appie";
213 $this->version = $regs[1];
216 elseif (ereg("larbin_([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
217 $this->brand = "larbin";
218 $this->version = $regs[1];
221 elseif (ereg("Gulper Web Bot ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
222 $this->brand = "Gulper Web Bot";
223 $this->version = $regs[1];
226 elseif (ereg("HTTrack ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
227 $this->brand = "HTTrack";
228 $this->version = $regs[1];
231 elseif (ereg("OWR_Crawler ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
232 $this->brand = "OWR_Crawler";
233 $this->version = $regs[1];
236 elseif (ereg("search.ch ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
237 $this->brand = "search.ch";
238 $this->version = $regs[1];
241 elseif (ereg("WebFilter Robot ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
242 $this->brand = "WebFilter Robot";
243 $this->version = $regs[1];
246 elseif (ereg("^LinkWalker", $this->uastring)) {
247 $this->brand = "LinkWalker";
251 elseif (ereg("^Internet Explorer 5.5", $this->uastring)) {
252 $this->brand = "Unknown bot (IE5.5)";
256 elseif (ereg("^Mozilla[\s ]*$", $this->uastring)) {
257 $this->brand = "Unknown bot (Mozilla)";
261 elseif (ereg("^BaiDuSpider", $this->uastring)) {
262 $this->brand = "BaiDuSpider";
266 elseif (ereg("^ia_archiver", $this->uastring)) {
267 $this->brand = "ia_archiver";
271 elseif (ereg("^PingALink", $this->uastring)) {
272 $this->brand = "PingALink";
276 elseif (ereg("^IlTrovatore-Setaccio", $this->uastring)) {
277 $this->brand = "IlTrovatore-Setaccio";
281 elseif (ereg("^Nutch", $this->uastring)) {
282 $this->brand = "Nutch";
286 elseif (ereg("^dumbBot", $this->uastring)) {
287 $this->brand = "dumbBot";
291 elseif (ereg("http://www.almaden.ibm.com/cs/crawler", $this->uastring)) {
292 $this->brand = "almaden crawler";
296 elseif (ereg("B-l-i-t-z-B-O-T", $this->uastring) || ereg("B l i t z B O T @ t r i c u s . n e t", $this->uastring)) {
297 $this->brand = "BlitzBOT";
301 elseif (ereg("sitecheck.internetseer.com", $this->uastring)) {
302 $this->brand = "internetseer";
306 elseif (ereg("Girafabot", $this->uastring)) {
307 $this->brand = "Girafabot";
311 elseif (ereg("efp@gmx.net", $this->uastring)) {
312 $this->brand = "efp";
316 elseif (ereg("HeinrichderMiragoRobot", $this->uastring)) {
317 $this->brand = "HeinrichderMiragoRobot";
321 elseif (ereg("MSIE ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
322 $this->brand = "Microsoft Internet Explorer";
323 $this->version = $regs[1];
325 elseif (ereg("Mozilla/([0-9a-zA-Z\.+]+)", $this->uastring, $regs) && !strstr($this->uastring, "compatible;") && !strstr($this->uastring, "Gecko/")) {
326 $this->brand = "Netscape";
327 $this->version = $regs[1];
328 if (intval($this->version) == 4) { $this->brand .= " Communicator"; }
331 $botArray = array("Scooter","Spinne","Vagabondo","TurnitinBot","FAST-WebCrawler","Firefly","Googlebot",
332 "Scrubby","psbot","NG","URL_Spider_Pro","Pompos","Szukacz","ASPseek","NPBot-1",
333 "dloader(NaverRobot)","NetResearchServer","","","","","","","");
335 if (in_array($this->brand, $botArray)) {
340 function getBrand() { return $this->brand; }
341 function getVersion() { return $this->version; }
342 function getUAString() { return $this->uastring; }
343 function isbot() { return $this->bot; }
346 if (!isset($this->uadata["is_ns"])) {
347 $this->uadata["is_ns"] = false;
348 if (strstr($this->brand, "Netscape")) {
349 $this->uadata["is_ns"] = true;
352 return $this->uadata["is_ns"];
356 if (!isset($this->uadata["is_ns4"])) {
357 $this->uadata["is_ns4"] = false;
358 if (strstr($this->brand, "Netscape") && (intval($this->version) == 4)) {
359 $this->uadata["is_ns4"] = true;
362 return $this->uadata["is_ns4"];
366 if (!isset($this->uadata["is_ie"])) {
368 if (strstr($this->brand, "Internet Explorer")) {
369 $this->uadata["is_ie"] = true;
372 return $this->uadata["is_ie"];
375 function geckobased() {
376 if (!isset($this->uadata["is_gecko"])) {
377 $this->uadata["is_gecko"] = false;
378 if (strstr($this->uastring, "Gecko/")) {
379 $this->uadata["is_gecko"] = true;
382 return $this->uadata["is_gecko"];
385 function geckodate() {
386 if (!isset($this->uadata["gdate"])) {
387 $this->uadata["gdate"] = 0;
388 if (ereg("Gecko/([0-9]+)", $this->uastring, $regs)) {
389 $this->uadata["gdate"] = $regs[1];
392 return $this->uadata["gdate"];
395 function khtmlbased() {
396 if (!isset($this->uadata["is_khtml"])) {
397 $this->uadata["is_khtml"] = false;
398 if (strstr($this->brand, "Konqueror") || strstr($this->brand, "Safari") || strstr($this->brand, "AppleWebKit")) {
399 $this->uadata["is_khtml"] = true;
402 return $this->uadata["is_khtml"];