|
< ><?php<BR>//原作者:epsilon7 <BR>//SonyMusic(<A href="mailto:sonymusic@163.net"><U><FONT color=#0000ff>sonymusic@163.net</FONT></U></A>) <BR>class BrowserDetector { <BR>var $UA = ""; //$HTTP_USER_AGENT的内容 <BR>var $BROWSER= "Unknown"; //浏览器类型 <BR>var $PLATFORM = "Unknown"; //操作系统 <BR>var $VERSION= ""; //浏览器版本号 <BR>var $MAJORVER = ""; //浏览器主版本号 <BR>var $MINORVER = ""; //浏览器副版本号 <BR>/* 构造函数开始 */ <BR>function BrowserDetector(){ <BR>$this->UA = getenv(HTTP_USER_AGENT); <BR>$preparens = ""; <BR>$parens = ""; <BR>$i = strpos($this->UA,"("); <BR>if ($i >= 0) { <BR>$preparens = trim(substr($this->UA,0,$i)); <BR>$parens = substr($this->UA,$i+1,strlen($this->UA)); <BR>$j = strpos($parens,")"); <BR>if($j>=0) { <BR>$parens = substr($parens,0,$j); <BR>} <BR>} <BR>else { <BR>$preparens = $this->UA; <BR>} <BR>$browVer = $preparens; <BR>$token = trim(strtok($parens,";")); <BR>while($token) { <BR>if($token=="compatible") { <BR>} <BR>elseif(preg_match("/MSIE/i","$token")) { <BR>$browVer = $token; <BR>} <BR>elseif(preg_match("/Opera/i","$token")) { <BR>$browVer = $token; <BR>} <BR>elseif(preg_match("/X11/i","$token") || preg_match("/SunOS/i","$token") || preg_match ("/Linux/i","$token")) { <BR>$this-> LATFORM = "Unix"; <BR>} <BR>elseif(preg_match("/Win/i","$token")) { <BR>$this-> LATFORM = $token; <BR>} <BR>elseif(preg_match("/Mac/i","$token") || preg_match("/PPC/i","$token")) { <BR>$this-> LATFORM = $token; <BR>} <BR>$token = strtok(";"); <BR>} <BR>$msieIndex = strpos($browVer,"MSIE"); <BR>if($msieIndex >= 0) { <BR>$browVer = substr($browVer,$msieIndex,strlen($browVer)); <BR>} <BR>$leftover = ""; <BR>if(substr($browVer,0,strlen("Mozilla")) == "Mozilla") { <BR>$this->BROWSER = "Netscape"; <BR>$leftover=substr($browVer,strlen("Mozilla")+1,strlen($browVer)); <BR>} <BR>elseif(substr($browVer,0,strlen("Lynx")) == "Lynx") { <BR>$this->BROWSER = "Lynx"; <BR>$leftover=substr($browVer,strlen("Lynx")+1,strlen($browVer)); <BR>} <BR>elseif(substr($browVer,0,strlen("MSIE")) == "MSIE") { <BR>$this->BROWSER = "IE"; <BR>$leftover=substr($browVer,strlen("MSIE")+1,strlen($browVer)); <BR>} <BR>elseif(substr($browVer,0,strlen("Microsoft Internet Explorer")) == "Microsoft Internet Explorer") { <BR>$this->BROWSER = "IE"; <BR>$leftover=substr($browVer,strlen("Microsoft Internet Explorer")+1,strlen($browVer)); <BR>} <BR>elseif(substr($browVer,0,strlen("Opera")) == "Opera") { <BR>$this->BROWSER = "Opera"; <BR>$leftover=substr($browVer,strlen("Opera")+1,strlen($browVer)); <BR>} <BR>$leftover = trim($leftover); <BR>$i=strpos($leftover," "); <BR>if($i > 0) { <BR>$this->VERSION = substr($leftover,0,$i); <BR>} <BR>else { <BR>$this->VERSION = $leftover; <BR>} <BR>$j = strpos($this->VERSION,"."); <BR>if($j >= 0) { <BR>$this->MAJORVER = substr($this->VERSION,0,$j); <BR>$this->MINORVER = substr($this->VERSION,$j+1,strlen($this->VERSION)); <BR>} <BR>else { <BR>$this->MAJORVER = $this->VERSION; <BR>} <BR>} <BR>} </P>< >//测试程序开始 <BR>$test=new browserdetector; <BR>echo $test->UA."<br>"; <BR>echo $test->BROWSER."<br>"; <BR>echo $test-> LATFORM."<br>"; <BR>echo $test->VERSION."<br>"; <BR>echo $test->MAJORVER."<br>"; <BR>echo $test->MINORVER."<br>"; <BR>?></P> |
|