This article mainly introduces the PHP detection useragent version of the example, the need for friends can refer to the following
Code as follows: <?php define (' IE ', 1); Define (' FIREFOX ', 2); Define (' CHROME ', 3); Define (' OPERA ', 4); Class Useragentdetect { static $version = Array () static $userAgent = ';   ; static function getuseragent () : $header = Getallheaders (); Self:: $userAgent = $header [' user-agent ']; } function Finduseragentbykey ($ua, $key) { $len = str Len ($key); $start = Strpos ($ua, $key); $pos = Strpos ($ua, ', $start + $len + 1); return substr ($ua, $start + $len, $pos-$len-$start); } static function detectuseragent () { se LF:: Getuseragent (); if (Strpos (self:: $userAgent, ' MSIE ')!= null) { self:: $version [] = IE; &NB Sp Self:: $version [] =self:: Finduseragentbykey (self:: $userAgent, ' msie '); } ELSE if (Strpos (self:: $userAgent, ' gecko/')!= null &NB Sp { , self:: $version [] = FIREFOX Self:: $version [] =self:: finduseragentbykey (self:: $userAgent, ' firefox/'); } ELSE if Strpos (self:: $userAgent, ' applewebkit/')!= nul L) { self:: $version [] = CHROME; &NBS P Self:: $version [] = self:: Finduseragentbykey (self:: $userAgent, ' chrome/'); } ELSE if (Strpos (selF:: $userAgent, ' presto/')!= null) { self:: $vers Ion[] = OPERA; self:: $version [] = self:: Finduseragentbykey (self:: $userAgent, ' opera/'); } else { &N Bsp } return self:: $version; } function matchuseragent ($ua, $key) { Preg_match ("/$key. ( [^s]*?] S/", $ua, $out); return $out [1]; } } $ua =useragentdetect::d etectuseragent (); Print_r ($ua);