[PHP] Détecter navigateur + système d'exploitation [Résolu]

Détecter navigateur + système d'exploitation [Résolu] [PHP] - PHP - Programmation

Marsh Posté le 05-03-2012 à 00:05:52    

Bonjour, je vous présente mes 2 fonctions :
 
-detect_browser() => Cette fonction détecte 98% des navigateur ...
-detect_os() => Cette fonction détecte 98% des systèmes d'exploitations ...
 
Bien sur à condition que l'utilisateur n'ai pas modifié la variable HTTP_USER_AGENT dans son navigateur.
Ce sont les 2 fonctions les plus complètes que je connaisse à ce jour.  Qu'en pensez vous ?
 
detect_browser()  

Citation :

function detect_browser(){$a=$_SERVER['HTTP_USER_AGENT'];$a=str_replace('+',' ',$a);$z=strrev(trim($a));if($z[0]==')') return 'Navigateur non précisé';$b='[\s\/]([0-9v]{1,7}(?:\.[0-9a-z]{1,7}){0,7})';if (preg_match('#firefox'.$b.'#i',$a,$c))return('Firefox version '.$c[1]);if (preg_match('#msie'.$b.'#i',$a,$c))return('Microsoft Internet Explorer version '.$c[1]);if (preg_match('#chrome'.$b.'#i',$a,$c))return('Google Chrome version '.$c[1]);if (preg_match('#icab'.$b.'#i',$a,$c))return('iCab (Crystal Atari Browser) version '.$c[1]);if (preg_match('#microsoft\sPocket\sinternet\sexplorer'.$b.'#i',$a,$c))return('Microsoft Pocket Internet Explorer version '.$c[1]);if (preg_match('#mspie'.$b.'#i',$a,$c))return('Microsoft Pocket Internet Explorer version '.$c[1]);if (preg_match('#konqueror'.$b.'#i',$a,$c))return('Konqueror version '.$c[1]);if (preg_match('#lunascape'.$b.'#i',$a,$c))return('Lunascape version '.$c[1]);if (preg_match('#lynx'.$b.'#i',$a,$c))return('Lynx version '.$c[1]);if (preg_match('#minimo'.$b.'#i',$a,$c))return('Minimo version '.$c[1]);if (preg_match('#netscape[0-9]?'.$b.'#i',$a,$c))return('Netscape version '.$c[1]);if (preg_match('#^nokia([^\/]+)\/([0-9v]{1,7}(?:\.[0-9a-z]{1,7}){0,7})#i',$a,$c))return('Nokia '.trim($c[1]).' version '.$c[2]);if (preg_match('#offbyone;#i',$a))return('OffByOne');if (preg_match('#omniweb'.$b.'#i',$a,$c))return('Omniweb version '.$c[1]);if (preg_match('#opera'.$b.'#i',$a,$c))return('Opera version '.$c[1]);if (preg_match('#safari'.$b.'#i',$a,$c))return('Safari version '.$c[1]);if (preg_match('#seamonkey'.$b.'#i',$a,$c))return('SeaMonkey version '.$c[1]);if (preg_match('#w3m'.$b.'#i',$a,$c))return('W3m version '.$c[1]);if (preg_match('#ia_archiver#i',$a))return('Alexa Bot');if (preg_match('#ask\sjeeves#i',$a))return('Ask Jeeves Bot');if (preg_match('#curl'.$b.'#i',$a,$c))return('Curl version '.$c[1]);if (preg_match('#exabot'.$b.'#i',$a,$c))return('Exaled bot version '.$c[1]);if (preg_match('#ng'.$b.'#i',$a,$c))return('Exaled bot version '.$c[1]);if (preg_match('#exabot-thumbnails#i',$a))return('Exaled bot');if (preg_match('#gamespyhttp'.$b.'#i',$a,$c))return('GameSpy Industries bot version '.$c[1]);if (preg_match('#gigabot'.$b.'#i',$a,$c))return('Gigablast bot version '.$c[1]);if (preg_match('#googlebot'.$b.'#i',$a,$c))return('Google bot version '.$c[1]);if (preg_match('#googlebot-image'.$b.'#i',$a,$c))return('Google bot (image) version '.$c[1]);if (preg_match('#grub-client[\s\/\-]([0-9v]{1,7}(?:\.[0-9a-z]{1,7}){0,7})#i',$a,$c))return('LookSmart Grub bot version '.$c[1]);if (preg_match('#yahoo! slurp#i',$a))return('Yahoo! Search bot');if (preg_match('#slurp#i',$a))return('Inktomi Slurp bot');if (preg_match('#msnbot'.$b.'#i',$a,$c))return('Microsoft MSN Search bot version '.$c[1]);if (preg_match('#scooter[\s\/\-]([0-9v]{1,7}(?:\.[0-9a-z]{1,7}){0,7})#i',$a,$c))return('AltaVista Scooter bot version '.$c[1]);if (preg_match('#wget'.$b.'#i',$a,$c))return('Wget bot version '.$c[1]);if (preg_match('#w3c_validator'.$b.'#i',$a,$c))return('W3C validator bot version '.$c[1]);if (preg_match('#firebird'.$b.'#i',$a,$c))return('Mozilla Firebird version '.$c[1]);if (preg_match('#Iceweasel'.$b.'#i',$a,$c))return('Iceweasel version '.$c[1]);if (preg_match('#galeon'.$b.'#i',$a,$c))return('Galeon version '.$c[1]);if (preg_match('#dejavu\.org#i',$a))return('dejavu.org');if (preg_match('#applewebkit'.$b.'#i',$a,$c))return('Safari version '.$c[1]);if (preg_match('#screenbrowser'.$b.'#i',$a,$c))return('Internet ScreenBrowser version '.$c[1]);if (preg_match('#depspid\.net#i',$a))return('DepSpid bot');if (preg_match('#scej#i',$a))return('SCEJ');if (preg_match('#playstation\sportable#i',$a))return('NetFront');if (preg_match('#netfront#i',$a))return('NetFront');if (preg_match('#semc#i',$a))return('SEMC');if (preg_match('#lizard#i',$a))return('Lizard');if (preg_match('#scoutjet\.com#i',$a))return('Scoutjet.com bot');if (preg_match('#proximic\.com#i',$a))return('Proximic.com bot');if (preg_match('#vwp-online\.de#i',$a))return('Vwp-online.de bot');if (preg_match('#icvn\.de#i',$a))return('Icvn.de bot');if (preg_match('#vbseo\.com#i',$a))return('Vbseo.com bot');if (preg_match('#spydom\.de#i',$a))return('SpyDom.de bot');if (preg_match('#uc\s?browser#i',$a))return('UC Browser');if (preg_match('#gecko#i',$a))return('Navigateur inconnu basé sur Gecko');if (preg_match('#netscape#i',$a))return('Netscape');if (preg_match('#funnelback#i',$a))return('Funnelback bot');if (preg_match('#linkman#i',$a))return('Linkman bot');if (preg_match('#teleca#i',$a))return('Teleca');return 'Navigateur non identifié';}


 
 
detect_os()  

Citation :

function detect_os(){$a=$_SERVER['HTTP_USER_AGENT'];$a=str_replace('+',' ',$a);if (preg_match('#windows\snt\s5\.1#i',$a))return('Microsoft Windows XP');if (preg_match('#linux\sx86_64#i',$a))return('Linux (64 bits)');if (preg_match('#libwww-fm#i',$a))return('Linux');if (preg_match('#freebsd#i',$a))return('FreeBSD');if (preg_match('#mac\sos\sx#i',$a))return('Mac OS X');if (preg_match('#windows\snt\s6\.1#i',$a))return('Microsoft Windows 7');if (preg_match('#haiku#i',$a))return('Haiku');if (preg_match('#windows\snt\s6\.0;\swow64#i',$a))return('Microsoft Windows Vista (64bits)');if (preg_match('#windows\snt\s6\.0;\swin64#i',$a))return('Microsoft Windows Vista (64bits)');if (preg_match('#windows\snt\s6\.0#i',$a))return('Microsoft Windows Vista');if (preg_match('#sunos#i',$a))return('Open Solaris');if (preg_match('#android#i',$a))return('Android');if (preg_match('#windows\s95#i',$a))return('Microsoft Windows 95');if (preg_match('#windows\snt\s5\.0#i',$a))return('Microsoft Windows 2000');if (preg_match('#windows\snt\s5\.3#i',$a))return('Microsoft Windows Server 2003');if (preg_match('#windows\snt#i',$a))return('Microsoft Windows NT');if (preg_match('#windows\s98#i',$a))return('Microsoft Windows 98');if (preg_match('#windows\sce#i',$a))return('Microsoft Windows Mobile');if (preg_match('#windows\sphone\sos[\s\/]([0-9v]{1,7}(?:\.[0-9a-z]{1,7}){0,7})#i',$a,$c))return('Microsoft Windows Phone version '.$c[1]);if (preg_match('#mac_powerpc#i',$a))return('Mac OS X');if (preg_match('#macintosh#i',$a))return('Macintosh');if (preg_match('#cygwin_nt#i',$a))return('Microsoft Windows 2000');if (preg_match('#os\/2#i',$a))return('Microsoft OS/2');if (preg_match('#symb(?:ian)#i',$a,$c))return('Symbian OS');if (preg_match('#symbian-crystal[\s\/]([0-9v]{1,7}(?:\.[0-9a-z]{1,7}){0,7})#i',$a,$c))return('Symbian OS version '.$c[1]);if (preg_match('#offbyone;\swindows\s2000#i',$a))return('Microsoft Windows XP');if (preg_match('#windows\s2000#i',$a))return('Microsoft Windows 2000');if (preg_match('#nintendo\swii#i',$a))return('Nintendo Wii');if (preg_match('#playstation\sportable#i',$a))return('PlayStation Portable');if (preg_match('#iphone\sos\s[\s\/]([0-9v]{1,7}(?:[\._][0-9a-z]{1,7}){0,7})#i',$a,$c))return('iPhone OS version '.$c[1]);if (preg_match('#nokia\s?([^\/]+)#i',$a,$c))return('Nokia'.$c[1]);if (preg_match('#najdi\.si#i',$a))return('Najdi.si');if (preg_match('#beos#i',$a))return('BeOS');if (preg_match('#fedora#i',$a))return('Fedora');if (preg_match('#openvms#i',$a))return('Open Virtual Memory System');if (preg_match('#openbsd#i',$a))return('OpenBSD');if (preg_match('#ask\.com#i',$a))return('Ask.com');if (preg_match('#tinybrowser\.com#i',$a))return('Tiny');if (preg_match('#whoisde\.de#i',$a))return('Whoisde.de');if (preg_match('#heritrix#i',$a))return('Heritrix (Internet Archive) bot');if (preg_match('#Amigaos#i',$a))return('AmigaOS');if (preg_match('#depspid\.net#i',$a))return('DepSpid');if (preg_match('#dejavu\.org#i',$a))return('Emulateur de navigateur');if (preg_match('#psp\s#i',$a))return('PlayStation Portable');if (preg_match('#\spsp#i',$a))return('PlayStation Portable');if (preg_match('#sonyericsson\s?([^\/]+)#i',$a,$c))return('Sony Ericsson '.$c[1]);if (preg_match('#windows\s7#i',$a))return('Microsoft Windows 7');if (preg_match('#windows\sme#i',$a))return('Microsoft Windows Millenium');if (preg_match('#nt\s5\.1#i',$a))return('Microsoft Windows XP');if (preg_match('#winnt#i',$a))return('Microsoft Windows NT');if (preg_match('#win98#i',$a))return('Microsoft Windows 98');if (preg_match('#win95#i',$a))return('Microsoft Windows 95');if (preg_match('#netbsd#i',$a))return('NetBSD basé sur UNIX');if (preg_match('#irix64#i',$a))return('Irix (64bits) basé sur UNIX');if (preg_match('#irix#i',$a))return('Irix basé sur UNIX');if (preg_match('#cerberian#i',$a))return('Cerberian');if (preg_match('#win\s9x\s4.0#i',$a))return('Microsoft Windows 95');if (preg_match('#win\s9x\s4.90#i',$a))return('Microsoft Windows Millennium');if (preg_match('#win\s9x\s4.1#i',$a))return('Microsoft Windows 98');if (preg_match('#windows\s3\.1#i',$a))return('Microsoft Windows 3.1');if (preg_match('#j2me#i',$a))return('Java 2 Platform');if (preg_match('#playstation\s?3#i',$a))return('PlayStation 3');if (preg_match('#blackberry#i',$a))return('BlackBerry OS');if (preg_match('#iphone#i',$a))return('iPhone');if (preg_match('#linux#i',$a))return('Linux');if (preg_match('#windows#i',$a))return('Microsoft Windows');return 'OS non identifié';}


 
pour les tester  

Citation :

echo 'Votre OS est '.detect_os().', votre navigateur est '.detect_browser().'.';die();


Message édité par mmike57 le 05-03-2012 à 00:19:19
Reply

Marsh Posté le 05-03-2012 à 00:05:52   

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed