>  기사  >  php教程  >  php 获取用户浏览器版本代码

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

WBOY
WBOY원래의
2016-06-13 11:24:07803검색

php 获取用户浏览器版本代码在php中我们有个全局变量$_SERVER['HTTP_USER_AGENT'];可以获取用户所有信息,我们要经过处理才可以判断用户浏览器是那种型的,下面的函数就可以准确的用户浏览器版本号代码。

php教程 获取用户浏览器版本代码
在php中我们有个全局变量$_server['http_user_agent'];可以获取用户所有信息,我们要经过处理才可以判断用户浏览器是那种型的,下面的函数就可以准确的用户浏览器版本号代码。

function getbrowse()
        {
                $agent = $_server['http_user_agent'];
                $browser = '';
                $browserver = '';
                $browser = array('lynx', 'mosaic', 'aol', 'opera', 'java', 'macweb', 'webexplorer', 'omniweb');
                for($i = 0; $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


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.