程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 一個浏覽器檢查類

一個浏覽器檢查類

編輯:關於PHP編程

//原作者:epsilon7
//SonyMusic([email protected])
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);  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved