一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php 获取用户浏览器版本代码

时间:2022-06-24 18:32:09 编辑:袖梨 来源:一聚教程网


function getbrowse()
        {
                $agent = $_server['http_user_agent'];
                $browser = '';
                $browserver = '';
                $browser = array('lynx', 'mosaic', 'aol', 'opera', 'java', 'macweb', 'webexplorer', 'omniweb');
                for($i = 0; $i <= 7; $i ++){
                        if(strpos($agent, $browsers[$i])){
                                $browser = $browsers[$i];
                                $browserver = '';
                        }
                }
                if(ereg('mozilla', $agent) && !ereg('msie', $agent)){
                        $temp = explode('(', $agent);
                        $part = $temp[0];
                        $temp = explode('/', $part);
                        $browserver = $temp[1];
                        $temp = explode(' ', $browserver);
                        $browserver = $temp[0];
                        $browserver = preg_replace('/([d.]+)/', '1', $browserver);
                        $browserver = $browserver;
                        $browser = 'netscape navigator';
                }
                if(ereg('mozilla', $agent) && ereg('opera', $agent)) {
                        $temp = explode('(', $agent);
                        $part = $temp[1];
                        $temp = explode(')', $part);
                        $browserver = $temp[1];
                        $temp = explode(' ', $browserver);
                        $browserver = $temp[2];
                        $browserver = preg_replace('/([d.]+)/', '1', $browserver);
                        $browserver = $browserver;
                        $browser = 'opera';
                }
                if(ereg('mozilla', $agent) && ereg('msie', $agent)){
                        $temp = explode('(', $agent);
                        $part = $temp[1];
                        $temp = explode(';', $part);
                        $part = $temp[1];
                        $temp = explode(' ', $part);
                        $browserver = $temp[2];
                        $browserver = preg_replace('/([d.]+)/','1',$browserver);
                        $browserver = $browserver;
                        $browser = 'internet explorer';
                }
                if($browser != ''){
                        $browseinfo = $browser.' '.$browserver;
                } else {
                        $browseinfo = false;
                }
                return $browseinfo;
        }
 //应用方法
 
 //在ie中
 echo getbrowse(); //internet explorer 6.0
 //在firefox中
 echo getbrowse() ;//netscape navigator 5.0

热门栏目