Copy CodeThe code is as follows:
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 = strlen ($key);
$start = Strpos ($ua, $key);
$pos = Strpos ($ua, ", $start + $len + 1);
Return substr ($ua, $start + $len, $pos-$len-$start);
}
static function Detectuseragent ()
{
Self:: Getuseragent ();
if (Strpos (self:: $userAgent, ' MSIE ')! = null)
{
Self:: $version [] = IE;
Self:: $version [] =self:: Finduseragentbykey (self:: $userAgent, ' MSIE ');
}
else if (Strpos (self:: $userAgent, ' gecko/')! = null)
{
Self:: $version [] = FIREFOX;
Self:: $version [] =self:: Finduseragentbykey (self:: $userAgent, ' firefox/');
}
else if (Strpos (self:: $userAgent, ' applewebkit/')! = null)
{
Self:: $version [] = CHROME;
Self:: $version [] = self:: Finduseragentbykey (self:: $userAgent, ' chrome/');
}
else if (Strpos (self:: $userAgent, ' presto/')! = null)
{
Self:: $version [] = OPERA;
Self:: $version [] = self:: Finduseragentbykey (self:: $userAgent, ' opera/');
}
Else
{
}
Return self:: $version;
}
function Matchuseragent ($ua, $key)
{
Preg_match ("/$key. ( [^\s]*?] \s/", $ua, $out);
return $out [1];
}
}
$ua =useragentdetect::d etectuseragent ();
Print_r ($ua);
http://www.bkjia.com/PHPjc/745210.html www.bkjia.com true http://www.bkjia.com/PHPjc/745210.html techarticle Copy the code as follows: PHP define (' IE ', 1); define (' FIREFOX ', 2); define (' CHROME ', 3); define (' OPERA ', 4); Class Useragentdetect {Static $version = array (); static $userAgent ...