blob: 33e8451c686e60e01340c83ab30f376b0fd5e0d4 [file] [log] [blame]
admindf752b22006-10-08 07:17:13 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * User Agent Class
20 *
21 * Identifies the platform, browser, robot, or mobile devise of the browsing agent
22 *
23 * @package CodeIgniter
24 * @subpackage Libraries
25 * @category User Agent
26 * @author Rick Ellis
27 * @link http://www.codeigniter.com/user_guide/libraries/uri.html
28 */
29class CI_User_agent {
30
31 var $agent = NULL;
32
33 var $is_browser = FALSE;
34 var $is_robot = FALSE;
35 var $is_mobile = FALSE;
36
37 var $platform = '';
38 var $browser = '';
39 var $version = '';
40 var $moble = '';
41 var $robot = '';
42
43
44 var $platforms = array (
45 'windows nt 6.0' => 'Windows Longhorn',
46 'windows nt 5.2' => 'Windows 2003',
47 'windows nt 5.0' => 'Windows 2000',
48 'windows nt 5.1' => 'Windows XP',
49 'windows nt 4.0' => 'Windows NT 4.0',
50 'winnt4.0' => 'Windows NT 4.0',
51 'winnt 4.0' => 'Windows NT',
52 'winnt' => 'Windows NT',
53 'windows 98' => 'Windows 98',
54 'win98' => 'Windows 98',
55 'windows 95' => 'Windows 95',
56 'win95' => 'Windows 95',
57 'windows' => 'Unknown Windows OS',
58 'mac os x' => 'Mac OS X',
59 'freebsd' => 'FreeBSD',
60 'ppc' => 'Macintosh',
61 'sunos' => 'Sun Solaris',
62 'linux' => 'Linux',
63 'debian' => 'Debian',
64 'beos' => 'BeOS',
65 'apachebench' => 'ApacheBench',
66 'aix' => 'AIX',
67 'irix' => 'Irix',
68 'osf' => 'DEC OSF',
69 'hp-ux' => 'HP-UX',
70 'netbsd' => 'NetBSD',
71 'bsdi' => 'BSDi',
72 'openbsd' => 'OpenBSD',
73 'gnu' => 'GNU/Linux',
74 'unix' => 'Unknown Unix OS'
75 );
76
77 var $browsers = array(
78 'Opera' => 'Opera',
79 'MSIE' => 'Internet Explorer',
80 'Internet Explorer' => 'Internet Explorer',
81 'Shiira' => 'Shiira',
82 'Firefox' => 'Firefox',
83 'Camino' => 'Camino',
84 'Mozilla' => 'Mozilla',
85 'Safari' => 'Safari',
86 'Konqueror' => 'Konqueror',
87 'Lynx' => 'Lynx',
88 'ANTFresco' => 'Fresco'
89 );
90
91 var $mobiles = array(
92 'mobileexplorer' => 'Mobile Explorer',
93 'openwave' => 'Open Wave',
94 'opera mini' => 'Opera Mini',
95 'operamini' => 'Opera Mini',
96 'elaine' => 'Palm',
97 'palmsource' => 'Palm',
98 'digital paths' => 'Palm',
99 'avantgo' => 'Avantgo',
100 'xiino' => 'Xiino',
101 'palmscape' => 'Palmscape',
102 'nokia' => 'Nokia',
103 'ericsson' => 'Ericsson',
104 'blackBerry' => 'BlackBerry',
105 'motorola' => 'Motorola'
106 );
107
108 var $robots = array(
109
110 'googlebot' => 'Googlebot',
111 'msnbot' => 'MSNBot',
112 'slurp' => 'Inktomi Slurp',
113 'yahoo' => 'Yahoo',
114 'askjeeves' => 'AskJeeves',
115 'fastcrawler' => 'FastCrawler',
116 'infoseek' => 'InfoSeek Robot 1.0',
117 'lycos' => 'Lycos',
118 'abcdatos' => 'ABCdatos BotLink',
119 'Acme.Spider' => 'Acme.Spider',
120 'ahoythehomepagefinder' => 'Ahoy! The Homepage Finder',
121 'Alkaline' => 'Alkaline',
122 'anthill' => 'Anthill',
123 'appie' => 'Walhello appie',
124 'arachnophilia' => 'Arachnophilia',
125 'arale' => 'Arale',
126 'araneo' => 'Araneo',
127 'araybot' => 'AraybOt',
128 'architext' => 'ArchitextSpider',
129 'aretha' => 'Aretha',
130 'ariadne' => 'ARIADNE',
131 'arks' => 'arks',
132 'aspider' => 'ASpider (Associative Spider)',
133 'atn.txt' => 'ATN Worldwide',
134 'atomz' => 'Atomz.com Search Robot',
135 'auresys' => 'AURESYS',
136 'backrub' => 'BackRub',
137 'bbot' => 'BBot',
138 'bigbrother' => 'Big Brother',
139 'bjaaland' => 'Bjaaland',
140 'blackwidow' => 'BlackWidow',
141 'blindekuh' => 'Die Blinde Kuh',
142 'Bloodhound' => 'Bloodhound',
143 'borg-bot' => 'Borg-Bot',
144 'boxseabot' => 'BoxSeaBot',
145 'brightnet' => 'bright.net caching robot',
146 'bspider' => 'BSpider',
147 'cactvschemistryspider' => 'CACTVS Chemistry Spider',
148 'calif' => 'Calif',
149 'cassandra' => 'Cassandra',
150 'cgireader' => 'Digimarc Marcspider/CGI',
151 'checkbot' => 'Checkbot',
152 'christcrawler' => 'ChristCrawler.com',
153 'churl' => 'churl',
154 'cienciaficcion' => 'cIeNcIaFiCcIoN.nEt',
155 'cmc' => 'CMC/0.01',
156 'Collective' => 'Collective',
157 'combine' => 'Combine System',
158 'confuzzledbot' => 'ConfuzzledBot',
159 'coolbot' => 'CoolBot',
160 'core' => 'Web Core / Roots',
161 'cosmos' => 'XYLEME Robot',
162 'cruiser' => 'Internet Cruiser Robot',
163 'cusco' => 'Cusco',
164 'cyberspyder' => 'CyberSpyder Link Test',
165 'cydralspider' => 'CydralSpider',
166 'desertrealm' => 'Desert Realm Spider',
167 'deweb' => 'DeWeb(c) Katalog/Index',
168 'dienstspider' => 'DienstSpider',
169 'digger' => 'Digger',
170 'diibot' => 'Digital Integrity Robot',
171 'directhit' => 'Direct Hit Grabber',
172 'dnabot' => 'DNAbot',
173 'download_express' => 'DownLoad Express',
174 'dragonbot' => 'DragonBot',
175 'e-collector' => 'e-collector',
176 'ebiness' => 'EbiNess',
177 'eit' => 'EIT Link Verifier Robot',
178 'elfinbot' => 'ELFINBOT',
179 'emacs' => 'Emacs-w3 Search Engine',
180 'emcspider' => 'ananzi',
181 'esculapio' => 'esculapio',
182 'esther' => 'Esther',
183 'evliyacelebi' => 'Evliya Celebi',
184 'nzexplorer' => 'nzexplorer',
185 'fdse' => 'Fluid Dynamics Search Engine robot',
186 'felix' => 'Felix IDE',
187 'ferret' => 'Wild Ferret Web Hopper #1, #2, #3',
188 'fetchrover' => 'FetchRover',
189 'fido' => 'fido',
190 'finnish' => 'Hämähäkki',
191 'fireball' => 'KIT-Fireball',
192 'fish' => 'Fish search',
193 'fouineur' => 'Fouineur',
194 'francoroute' => 'Robot Francoroute',
195 'freecrawl' => 'Freecrawl',
196 'funnelweb' => 'FunnelWeb',
197 'gama' => 'gammaSpider, FocusedCrawler',
198 'gazz' => 'gazz',
199 'gcreep' => 'GCreep',
200 'getbot' => 'GetBot',
201 'geturl' => 'GetURL',
202 'golem' => 'Golem',
203 'grapnel' => 'Grapnel/0.01 Experiment',
204 'griffon' => 'Griffon ',
205 'gromit' => 'Gromit',
206 'gulliver' => 'Northern Light Gulliver',
207 'gulperbot' => 'Gulper Bot',
208 'hambot' => 'HamBot',
209 'harvest' => 'Harvest',
210 'havindex' => 'havIndex',
211 'hi' => 'HI (HTML Index) Search',
212 'hometown' => 'Hometown Spider Pro',
213 'wired-digital' => 'Wired Digital',
214 'htdig' => 'ht://Dig',
215 'htmlgobble' => 'HTMLgobble',
216 'hyperdecontextualizer' => 'Hyper-Decontextualizer',
217 'iajabot' => 'iajaBot',
218 'ibm' => 'IBM_Planetwide',
219 'iconoclast' => 'Popular Iconoclast',
220 'Ilse' => 'Ingrid',
221 'imagelock' => 'Imagelock ',
222 'incywincy' => 'IncyWincy',
223 'informant' => 'Informant',
224 'infoseeksidewinder' => 'Infoseek Sidewinder',
225 'infospider' => 'InfoSpiders',
226 'inspectorwww' => 'Inspector Web',
227 'intelliagent' => 'IntelliAgent',
228 'irobot' => 'I, Robot',
229 'iron33' => 'Iron33',
230 'israelisearch' => 'Israeli-search',
231 'javabee' => 'JavaBee',
232 'JBot' => 'JBot Java Web Robot',
233 'jcrawler' => 'JCrawler',
234 'jobo' => 'JoBo Java Web Robot',
235 'jobot' => 'Jobot',
236 'joebot' => 'JoeBot',
237 'jubii' => 'The Jubii Indexing Robot',
238 'jumpstation' => 'JumpStation',
239 'kapsi' => 'image.kapsi.net',
240 'katipo' => 'Katipo',
241 'kdd' => 'KDD-Explorer',
242 'kilroy' => 'Kilroy',
243 'ko_yappo_robot' => 'KO_Yappo_Robot',
244 'labelgrabber.txt' => 'LabelGrabber',
245 'larbin' => 'larbin',
246 'legs' => 'legs',
247 'linkidator' => 'Link Validator',
248 'linkscan' => 'LinkScan',
249 'linkwalker' => 'LinkWalker',
250 'lockon' => 'Lockon',
251 'logo_gif' => 'logo.gif Crawler',
252 'magpie' => 'Magpie',
253 'marvin' => 'marvin/infoseek',
254 'mattie' => 'Mattie',
255 'mediafox' => 'MediaFox',
256 'merzscope' => 'MerzScope',
257 'meshexplorer' => 'NEC-MeshExplorer',
258 'MindCrawler' => 'MindCrawler',
259 'mnogosearch' => 'mnoGoSearch search engine software',
260 'moget' => 'moget',
261 'momspider' => 'MOMspider',
262 'monster' => 'Monster',
263 'motor' => 'Motor',
264 'muncher' => 'Muncher',
265 'muninn' => 'Muninn',
266 'muscatferret' => 'Muscat Ferret',
267 'mwdsearch' => 'Mwd.Search',
268 'myweb' => 'Internet Shinchakubin',
269 'NDSpider' => 'NDSpider',
270 'netcarta' => 'NetCarta WebMap Engine',
271 'netmechanic' => 'NetMechanic',
272 'netscoop' => 'NetScoop',
273 'newscan-online' => 'newscan-online',
274 'nhse' => 'NHSE Web Forager',
275 'nomad' => 'Nomad',
276 'northstar' => 'The NorthStar Robot',
277 'objectssearch' => 'ObjectsSearch',
278 'occam' => 'Occam',
279 'octopus' => 'HKU WWW Octopus',
280 'OntoSpider' => 'OntoSpider',
281 'openfind' => 'Openfind data gatherer',
282 'orb_search' => 'Orb Search',
283 'packrat' => 'Pack Rat',
284 'pageboy' => 'PageBoy',
285 'parasite' => 'ParaSite',
286 'patric' => 'Patric',
287 'pegasus' => 'pegasus',
288 'perignator' => 'The Peregrinator',
289 'perlcrawler' => 'PerlCrawler 1.0',
290 'phantom' => 'Phantom',
291 'phpdig' => 'PhpDig',
292 'pitkow' => 'html_analyzer',
293 'pjspider' => 'Portal Juice Spider',
294 'pka' => 'PGP Key Agent',
295 'poppi' => 'Poppi',
296 'portalb' => 'PortalB Spider',
297 'psbot' => 'psbot',
298 'Puu' => 'GetterroboPlus Puu',
299 'python' => 'The Python Robot',
300 'raven ' => 'Raven Search',
301 'rbse' => 'RBSE Spider',
302 'resumerobot' => 'Resume Robot',
303 'rhcs' => 'RoadHouse Crawling System',
304 'rixbot' => 'RixBot',
305 'roadrunner' => 'Road Runner: The ImageScape Robot',
306 'robbie' => 'Robbie the Robot',
307 'robi' => 'ComputingSite Robi/1.0',
308 'robocrawl' => 'RoboCrawl Spider',
309 'robofox' => 'RoboFox',
310 'robozilla' => 'Robozilla',
311 'roverbot' => 'Roverbot',
312 'rules' => 'RuLeS',
313 'safetynetrobot' => 'SafetyNet Robot',
314 'scooter' => 'Scooter',
315 'search_au' => 'Search.Aus-AU.COM',
316 'search-info' => 'Sleek',
317 'searchprocess' => 'SearchProcess',
318 'senrigan' => 'Senrigan',
319 'sgscout' => 'SG-Scout',
320 'shaggy' => 'ShagSeeker',
321 'sift' => 'Sift',
322 'simbot' => 'Simmany Robot Ver1.0',
323 'site-valet' => 'Site Valet',
324 'sitetech' => 'SiteTech-Rover',
325 'skymob' => 'Skymob.com',
326 'slcrawler' => 'SLCrawler',
327 'smartspider' => 'Smart Spider',
328 'snooper' => 'Snooper',
329 'solbot' => 'Solbot',
330 'speedy' => 'Speedy Spider',
331 'spider_monkey' => 'spider_monkey',
332 'spiderbot' => 'SpiderBot',
333 'spiderline' => 'Spiderline Crawler',
334 'spiderman' => 'SpiderMan',
335 'spiderview' => 'SpiderView(tm)',
336 'spry' => 'Spry Wizard Robot',
337 'ssearcher' => 'Site Searcher',
338 'suke' => 'Suke',
339 'suntek' => 'suntek search engine',
340 'sven' => 'Sven',
341 'sygol' => 'Sygol ',
342 'tach_bw' => 'TACH Black Widow',
343 'tarantula' => 'Tarantula',
344 'tarspider' => 'tarspider',
345 'tcl' => 'Tcl W3 Robot',
346 'techbot' => 'TechBOT',
347 'templeton' => 'Templeton',
348 'titin' => 'TitIn',
349 'titan' => 'TITAN',
350 'tkwww' => 'The TkWWW Robot',
351 'tlspider' => 'TLSpider',
352 'ucsd' => 'UCSD Crawl',
353 'udmsearch' => 'UdmSearch',
354 'ultraseek' => 'Ultraseek',
355 'uptimebot' => 'UptimeBot',
356 'urlck' => 'URL Check',
357 'valkyrie' => 'Valkyrie',
358 'verticrawl' => 'Verticrawl',
359 'victoria' => 'Victoria',
360 'visionsearch' => 'vision-search',
361 'voidbot' => 'void-bot',
362 'voyager' => 'Voyager',
363 'vwbot' => 'VWbot',
364 'w3index' => 'The NWI Robot',
365 'w3m2' => 'W3M2',
366 'wallpaper' => 'WallPaper (alias crawlpaper)',
367 'wanderer' => 'the World Wide Web Wanderer',
368 'wapspider' => 'w@pSpider by wap4.com',
369 'webbandit' => 'WebBandit Web Spider',
370 'webcatcher' => 'WebCatcher',
371 'webcopy' => 'WebCopy',
372 'webfetcher' => 'webfetcher',
373 'webfoot' => 'The Webfoot Robot',
374 'webinator' => 'Webinator',
375 'weblayers' => 'weblayers',
376 'weblinker' => 'WebLinker',
377 'webmirror' => 'WebMirror',
378 'webmoose' => 'The Web Moose',
379 'webquest' => 'WebQuest',
380 'webreader' => 'Digimarc MarcSpider',
381 'webreaper' => 'WebReaper',
382 'webs' => 'webs',
383 'websnarf' => 'Websnarf',
384 'webspider' => 'WebSpider',
385 'webvac' => 'WebVac',
386 'webwalk' => 'webwalk',
387 'webwalker' => 'WebWalker',
388 'webwatch' => 'WebWatch',
389 'wget' => 'Wget',
390 'whatuseek' => 'whatUseek Winona',
391 'whowhere' => 'WhoWhere Robot',
392 'wlm' => 'Weblog Monitor',
393 'wmir' => 'w3mir',
394 'wolp' => 'WebStolperer',
395 'wombat' => 'The Web Wombat ',
396 'worm' => 'The World Wide Web Worm',
397 'wwwc' => 'WWWC Ver 0.2.5',
398 'wz101' => 'WebZinger',
399 'xget' => 'XGET',
400 );
401
402
403
404 /**
405 * Constructor
406 *
407 * Sets the User Agent and runs the compilation routine
408 *
409 * @access public
410 * @return void
411 */
412 function CI_User_agent()
413 {
414 if (isset($_SERVER['HTTP_USER_AGENT']))
415 {
416 $this->agent = trim($_SERVER['HTTP_USER_AGENT']);
417 }
418
419 if ( ! is_null($this->agent))
420 {
421 $this->_compile_data();
422 }
423 }
424
425 // --------------------------------------------------------------------
426
427 /**
428 * Compile the User Agent Data
429 *
430 * @access private
431 * @return bool
432 */
433 function _compile_data()
434 {
435 $this->_set_platform();
436
437 foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function)
438 {
439 if ($this->$function() === TRUE)
440 {
441 break;
442 }
443 }
444 }
445
446 // --------------------------------------------------------------------
447
448 /**
449 * Set the Platform
450 *
451 * @access private
452 * @return mixed
453 */
454 function _set_platform()
455 {
456 foreach ($this->platforms as $key => $val)
457 {
458 if (preg_match("|$key|i", $this->agent))
459 {
460 $this->platform = $val;
461 return TRUE;
462 }
463 }
464
465 $this->platform = 'Unknown Platform';
466 }
467
468 // --------------------------------------------------------------------
469
470 /**
471 * Set the Browser
472 *
473 * @access private
474 * @return bool
475 */
476 function _set_browser()
477 {
478 foreach ($this->browsers as $key => $val)
479 {
480 if (preg_match("|".$key.".*?([0-9\.]+)|i", $this->agent, $match))
481 {
482 $this->is_browser = TRUE;
483 $this->version = $match[1];
484 $this->browser = $val;
485 return TRUE;
486 }
487 }
488
489 return FALSE;
490 }
491
492 // --------------------------------------------------------------------
493
494 /**
495 * Set the Robot
496 *
497 * @access private
498 * @return bool
499 */
500 function _set_robot()
501 {
502 foreach ($this->robots as $key => $val)
503 {
504 if (preg_match("|$key|i", $this->agent))
505 {
506 $this->is_robot = TRUE;
507 $this->robot = $val;
508 return TRUE;
509 }
510 }
511
512 return FALSE;
513 }
514
515 // --------------------------------------------------------------------
516
517 /**
518 * Set the Mobile Devise
519 *
520 * @access private
521 * @return bool
522 */
523 function _set_mobile()
524 {
525 foreach ($this->mobiles as $key => $val)
526 {
527 if (FALSE !== (strpos(strtolower($this->agent), $key)))
528 {
529 $this->is_mobile = TRUE;
530 $this->mobile = $val;
531 return TRUE;
532 }
533 }
534
535 return FALSE;
536 }
537
538
539 // --------------------------------------------------------------------
540
541 /**
542 * Is Browser
543 *
544 * @access public
545 * @return bool
546 */
547 function is_browser()
548 {
549 return $this->is_browser;
550 }
551
552 // --------------------------------------------------------------------
553
554 /**
555 * Is Robot
556 *
557 * @access public
558 * @return bool
559 */
560 function is_robot()
561 {
562 return $this->is_robot;
563 }
564
565 // --------------------------------------------------------------------
566
567 /**
568 * Is Mobile
569 *
570 * @access public
571 * @return bool
572 */
573 function is_mobile()
574 {
575 return $this->is_mobile;
576 }
577
578 // --------------------------------------------------------------------
579
580 /**
581 * Get Platform
582 *
583 * @access public
584 * @return string
585 */
586 function get_platform()
587 {
588 return $this->platform;
589 }
590
591 // --------------------------------------------------------------------
592
593 /**
594 * Get Browser Name
595 *
596 * @access public
597 * @return string
598 */
599 function get_browser()
600 {
601 return $this->browser;
602 }
603
604 // --------------------------------------------------------------------
605
606 /**
607 * Get the Browser Version
608 *
609 * @access public
610 * @return string
611 */
612 function get_version()
613 {
614 return $this->version;
615 }
616
617 // --------------------------------------------------------------------
618
619 /**
620 * Get The Robot Name
621 *
622 * @access public
623 * @return string
624 */
625 function get_robot()
626 {
627 return $this->robot;
628 }
629 // --------------------------------------------------------------------
630
631 /**
632 * Get the Mobile Devise
633 *
634 * @access public
635 * @return string
636 */
637 function get_mobile()
638 {
639 return $this->mobile;
640 }
641
642
643}
644
645?>