欢迎光临
我们一直在努力

一个浏览器检查类-PHP教程,PHP应用

建站超值云服务器,限时71元/月

一个浏览器检查类

<?php
//原作者:epsilon7
//sonymusic(sonymusic@163.net)
class browserdetector  {
    var $ua =  "";    //$http_user_agent的内容
    var $browser=  "unknown";    //浏览器类型
    var $platform   =  "unknown";    //操作系统
    var $version=  "";    //浏览器版本号
    var $majorver   =  "";    //浏览器主版本号
    var $minorver   =  "";    //浏览器副版本号
    /* 构造函数开始 */
    function browserdetector(){  
        $this->ua   =  getenv(http_user_agent);   
        $preparens  =  "";   
        $parens =  "";   
        $i = strpos($this->ua,"(");   
        if ($i >= 0)   {  
            $preparens  = trim(substr($this->ua,0,$i));  
            $parens = substr($this->ua,$i+1,strlen($this->ua));  
            $j = strpos($parens,")");  
            if($j>=0)  {  
                $parens = substr($parens,0,$j);  
            }   
        }   
        else   {  
            $preparens = $this->ua;   
        }   
        $browver =  $preparens;   
        $token  =  trim(strtok($parens,";"));   
        while($token)   {  
            if($token=="compatible")  {
            }  
            elseif(preg_match("/msie/i","$token"))  {  
                $browver = $token;  
            }  
            elseif(preg_match("/opera/i","$token"))  {  
                $browver = $token;  
            }  
            elseif(preg_match("/x11/i","$token") || preg_match("/sunos/i","$token") || preg_match ("/linux/i","$token"))  {  
                $this->platform   =  "unix";  
            }  
            elseif(preg_match("/win/i","$token"))  {  
                $this->platform   =  $token;  
            }  
            elseif(preg_match("/mac/i","$token") || preg_match("/ppc/i","$token"))  {  
                $this->platform   =  $token;  
            }  
            $token = strtok(";");   
        }   
        $msieindex  =  strpos($browver,"msie");   
        if($msieindex >= 0)   {  
            $browver =  substr($browver,$msieindex,strlen($browver));   
        }   
        $leftover   =  "";   
        if(substr($browver,0,strlen("mozilla")) == "mozilla")   {  
            $this->browser =  "netscape";  
            $leftover=substr($browver,strlen("mozilla")+1,strlen($browver));   
        }   
        elseif(substr($browver,0,strlen("lynx")) == "lynx")   {  
            $this->browser =  "lynx";  
            $leftover=substr($browver,strlen("lynx")+1,strlen($browver));   
        }   
        elseif(substr($browver,0,strlen("msie")) == "msie") {  
            $this->browser =  "ie";  
            $leftover=substr($browver,strlen("msie")+1,strlen($browver));   
        }   
        elseif(substr($browver,0,strlen("microsoft internet explorer")) == "microsoft internet  explorer")   {  
            $this->browser =  "ie";  
            $leftover=substr($browver,strlen("microsoft internet explorer")+1,strlen($browver));   
        }  
        elseif(substr($browver,0,strlen("opera")) == "opera")   {  
            $this->browser =  "opera";  
            $leftover=substr($browver,strlen("opera")+1,strlen($browver));   
        }   
        $leftover = trim($leftover);   
        $i=strpos($leftover," ");   
        if($i > 0)   {  
            $this->version = substr($leftover,0,$i);   
        }   
        else   {  
            $this->version = $leftover;   
        }   
        $j = strpos($this->version,".");   
        if($j >= 0)   {  
            $this->majorver = substr($this->version,0,$j);  
            $this->minorver = substr($this->version,$j+1,strlen($this->version));   
        }   
        else   {  
            $this->majorver = $this->version;   
        }
    }
}

//测试程序开始
$test=new browserdetector;
echo $test->ua."<br>";
echo $test->browser."<br>";
echo $test->platform."<br>";
echo $test->version."<br>";
echo $test->majorver."<br>";
echo $test->minorver."<br>";
?>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 一个浏览器检查类-PHP教程,PHP应用
分享到: 更多 (0)