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 // function getBrand()
19 // returns the User Agent Brand Name
20 // function getVersion()
21 // returns the User Agent version
24 // returns true if User Agent seems to be a bot
26 // returns true if User Agent seems to be Netscape brand, false if not
28 // returns true if User Agent seems to be Netscape Communicator 4.x, false if not
30 // returns true if User Agent seems to be a version of Internet Exploder, false if not
31 // function geckobased()
32 // returns true if User Agent seems to be a Gecko-based browser, false if not
33 // function geckodate()
34 // returns the Gecko date when it's a Gecko-based browser, 0 if not
35 // function khtmlbased()
36 // returns true if User Agent seems to be a KHTML-based browser, false if not
38 // collection of some known User Agent Strings:
39 // Mozilla/5.0 (compatible; Konqueror/3; Linux 2.4.18; X11; i686)
40 // Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.3b) Gecko/20030114
41 // Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt)
42 // Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)
43 // Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
44 // Mozilla/4.75 [de] (Win98; U)
45 // Opera/5.12 (Windows 2000; U) [de]
46 // Mozilla/5.0 (Windows; U; Win 9x 4.90; de-DE; m18) Gecko/20010131 Netscape6/6.01
47 // Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.0.1) Gecko/20020823 Netscape/7.0
48 // Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/51 (like Gecko) Safari/51
49 // Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6g
50 // Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20021109 Chimera/0.6+
51 // Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.3a) Gecko/20021207 Phoenix/0.5
52 // Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20021204
53 // Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.05 [ja]
54 // Mozilla/4.0 (compatible; MSIE 5.12; Mac_PowerPC) OmniWeb/4.1.1-v424.6
55 // Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6
56 // Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.5a) Gecko/20030728 Mozilla Firebird/0.6.1
58 // *** search bots: ***
61 // Vagabondo/2.0 MT (webagent at wise-guys dot nl)
62 // TurnitinBot/1.5 ( ">http://www.turnitin.com/robot/crawlerinfo.html)
63 // FAST-WebCrawler/3.x Multimedia (mm dash crawler at fast dot no)
64 // Firefly/1.0 (compatible; Mozilla 4.0; MSIE 5.5)
65 // Googlebot/2.1 (+ ">http://www.googlebot.com/bot.html)
66 // Scrubby/2.2 ( ">http://www.scrubtheweb.com/)
67 // psbot/0.1 (+ ">http://www.picsearch.com/bot.html)
69 // URL_Spider_Pro/3.0 ( ">http://www.innerprise.net/usp-spider.asp)"
70 // Pompos/1.3 ">http://dir.com/pompos.html
71 // Szukacz/1.5 (robot; www.szukacz.pl/jakdzialarobot.html; info@szukacz.pl)
74 // NetResearchServer/2.7(loopimprovements.com/robot.html)
75 // dloader(NaverRobot)/1.0
76 // Mozilla/4.0 compatible ZyBorg/1.0 Daily Refresh Beta-d03 (wn.zyborg@looksmart.net;
77 // Mozilla/2.0 (compatible; Ask Jeeves/Teoma)
78 // Mozilla/5.0 (Slurp/si; slurp@inktomi.com; ">http://www.inktomi.com/slurp.html)
79 // Mozilla/5.0 [en] (compatible; Gulper Web Bot 0.2.4 www.ecsl.cs.sunysb.edu/~maxim/cgi-bin/Link/GulperBot)
80 // Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; Girafabot; girafabot at girafa dot com;
81 // Mozilla/4.0 (efp@gmx.net)
82 // Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)
83 // PingALink Monitoring Services 1.0 (http://www.pingalink.com)
84 // IlTrovatore-Setaccio (+ ">http://www.iltrovatore.it)
86 // appie 1.1 (www.walhello.com)
87 // larbin_2.6.2 (larbin2.6.2@unspecified.mail)
89 // search.ch V1.4.2 (spiderman@search.ch;
90 // WebFilter Robot 1.0
91 // Openfind data gatherer, Openbot/3.0+(robot-response@openfind.com.tw;+
93 // Internet Explorer 5.5
95 // Mozilla/4.0 (compatible; B-l-i-t-z-B-O-T)
96 // B l i t z B O T @ t r i c u s . n e t (Mozilla compatible)
97 // sitecheck.internetseer.com (For more info see: ">http://sitecheck.internetseer.com)
98 // http://www.almaden.ibm.com/cs/crawler [c01]
102 // HeinrichderMiragoRobot
110 function userAgent($ua_string = "") {
111 // *** constructor ***
112 if (strlen($ua_string)) {
113 $this->uastring = $ua_string;
116 // read raw UA string
117 $this->uastring = $_SERVER["HTTP_USER_AGENT"];
120 // get UA brand and version
121 $this->brand = "Unknown"; $this->version = 0;
122 if (ereg("([0-9a-zA-Z\.()-]+)/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
123 $this->brand = $regs[1]; // this is a reasonable default :)
124 $this->version = $regs[2]; // this is a reasonable default :)
126 if (ereg("Netscape6/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
127 $this->brand = "Netscape";
128 $this->version = $regs[1];
130 elseif (ereg("Netscape/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
131 $this->brand = "Netscape";
132 $this->version = $regs[1];
134 elseif (ereg("Chimera/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
135 $this->brand = "Chimera";
136 $this->version = $regs[1];
138 elseif (ereg("Phoenix/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
139 $this->brand = "Phoenix";
140 $this->version = $regs[1];
142 elseif (ereg("Mozilla Firebird/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
143 $this->brand = "Mozilla Firebird";
144 $this->version = $regs[1];
146 elseif (ereg("Galeon/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
147 $this->brand = "Galeon";
148 $this->version = $regs[1];
150 elseif (ereg("rv:([0-9a-zA-Z\.+]+)", $this->uastring, $regs) && strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
151 $this->brand = "Mozilla";
152 $this->version = $regs[1];
154 elseif (ereg("Opera[ /]([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
155 $this->brand = "Opera";
156 $this->version = $regs[1];
158 elseif (ereg("OmniWeb/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
159 $this->brand = "OmniWeb";
160 $this->version = $regs[1];
162 elseif (ereg("Konqueror/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
163 $this->brand = "Konqueror";
164 $this->version = $regs[1];
166 elseif (ereg("Safari/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
167 $this->brand = "Safari";
168 $this->version = $regs[1];
170 elseif (ereg("AppleWebKit/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
171 $this->brand = "AppleWebKit";
172 $this->version = $regs[1];
174 elseif (ereg("ZyBorg/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
175 $this->brand = "ZyBorg";
176 $this->version = $regs[1];
179 elseif (ereg("Ask Jeeves/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
180 $this->brand = "Ask Jeeves";
181 $this->version = $regs[1];
184 elseif (ereg("Slurp/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
185 $this->brand = "Slurp";
186 $this->version = $regs[1];
189 elseif (ereg("Openbot/([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
190 $this->brand = "Openbot";
191 $this->version = $regs[1];
194 elseif (ereg("Mercator-([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
195 $this->brand = "Mercator";
196 $this->version = $regs[1];
199 elseif (ereg("appie ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
200 $this->brand = "appie";
201 $this->version = $regs[1];
204 elseif (ereg("larbin_([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
205 $this->brand = "larbin";
206 $this->version = $regs[1];
209 elseif (ereg("Gulper Web Bot ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
210 $this->brand = "Gulper Web Bot";
211 $this->version = $regs[1];
214 elseif (ereg("HTTrack ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
215 $this->brand = "HTTrack";
216 $this->version = $regs[1];
219 elseif (ereg("OWR_Crawler ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
220 $this->brand = "OWR_Crawler";
221 $this->version = $regs[1];
224 elseif (ereg("search.ch ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
225 $this->brand = "search.ch";
226 $this->version = $regs[1];
229 elseif (ereg("WebFilter Robot ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
230 $this->brand = "WebFilter Robot";
231 $this->version = $regs[1];
234 elseif (ereg("^LinkWalker", $this->uastring)) {
235 $this->brand = "LinkWalker";
239 elseif (ereg("^Internet Explorer 5.5", $this->uastring)) {
240 $this->brand = "Unknown bot (IE5.5)";
244 elseif (ereg("^Mozilla", $this->uastring)) {
245 $this->brand = "Unknown bot (Mozilla)";
249 elseif (ereg("^BaiDuSpider", $this->uastring)) {
250 $this->brand = "BaiDuSpider";
254 elseif (ereg("^ia_archiver", $this->uastring)) {
255 $this->brand = "ia_archiver";
259 elseif (ereg("^PingALink", $this->uastring)) {
260 $this->brand = "PingALink";
264 elseif (ereg("^IlTrovatore-Setaccio", $this->uastring)) {
265 $this->brand = "IlTrovatore-Setaccio";
269 elseif (ereg("^Nutch", $this->uastring)) {
270 $this->brand = "Nutch";
274 elseif (ereg("^dumbBot", $this->uastring)) {
275 $this->brand = "dumbBot";
279 elseif (ereg("http://www.almaden.ibm.com/cs/crawler", $this->uastring)) {
280 $this->brand = "almaden crawler";
284 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)) {
285 $this->brand = "BlitzBOT";
289 elseif (ereg("sitecheck.internetseer.com", $this->uastring)) {
290 $this->brand = "internetseer";
294 elseif (ereg("Girafabot", $this->uastring)) {
295 $this->brand = "Girafabot";
299 elseif (ereg("efp@gmx.net", $this->uastring)) {
300 $this->brand = "efp";
304 elseif (ereg("HeinrichderMiragoRobot", $this->uastring)) {
305 $this->brand = "HeinrichderMiragoRobot";
309 elseif (ereg("MSIE ([0-9a-zA-Z\.+]+)", $this->uastring, $regs)) {
310 $this->brand = "Microsoft Internet Explorer";
311 $this->version = $regs[1];
313 elseif (ereg("Mozilla/([0-9a-zA-Z\.+]+)", $this->uastring, $regs) && !strstr($this->uastring, "compatible;") && !strstr($this->uastring, "Gecko/")) {
314 $this->brand = "Netscape";
315 $this->version = $regs[1];
316 if (intval($this->version) == 4) { $this->brand .= " Communicator"; }
319 $botArray = array("Scooter","Spinne","Vagabondo","TurnitinBot","FAST-WebCrawler","Firefly","Googlebot",
320 "Scrubby","psbot","NG","URL_Spider_Pro","Pompos","Szukacz","ASPseek","NPBot-1",
321 "dloader(NaverRobot)","NetResearchServer","","","","","","","");
323 if (in_array($this->brand, $botArray)) {
328 function getBrand() { return $this->brand; }
329 function getVersion() { return $this->version; }
330 function isbot() { return $this->bot; }
333 // set it static so that we don't have to call it that often
335 if (!isset($is_ns)) {
337 if (strstr($this->brand, "Netscape")) {
345 // set it static so that we don't have to call it that often
347 if (!isset($is_ns4)) {
349 if (strstr($this->brand, "Netscape") && (intval($this->version) == 4)) {
357 // set it static so that we don't have to call it that often
359 if (!isset($is_ie)) {
361 if (strstr($this->brand, "Internet Explorer")) {
368 function geckobased() {
369 // set it static so that we don't have to call it that often
371 if (!isset($is_gecko)) {
373 if (strstr($this->uastring, "Gecko/")) {
380 function geckodate() {
381 // set it static so that we don't have to call it that often
383 if (!isset($gdate)) {
385 if (ereg("Gecko/([0-9]+)", $this->uastring, $regs)) {
392 function khtmlbased() {
393 // set it static so that we don't have to call it that often
395 if (!isset($is_khtml)) {
397 if (strstr($this->brand, "Konqueror") || strstr($this->brand, "Safari") || strstr($this->brand, "AppleWebKit")) {