Home > Backend Development > PHP Tutorial > A browser inspection class_PHP tutorial

A browser inspection class_PHP tutorial

WBOY
Release: 2016-07-13 17:31:37
Original
751 people have browsed it

//Original author: epsilon7
//SonyMusic(sonymusic@163.net)
class BrowserDetector {
var $UA = ""; //Content of $HTTP_USER_AGENT
var $BROWSER= "Unknown "; //Browser type
var $PLATFORM = "Unknown"; //Operating system
var $VERSION= ""; //Browser version number
var $MAJORVER = ""; // Browser major version number
var $MINORVER = ""; //Browser minor version number
/* Start constructor*/
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; 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);

http://www.bkjia.com/PHPjc/509060.html

truehttp: //www.bkjia.com/PHPjc/509060.htmlTechArticle//Original author: epsilon7 //SonyMusic(sonymusic@163.net) class BrowserDetector var UA = ""; //Content of HTTP_USER_AGENT var BROWSER= "Unknown"; //Browser type var PLATFORM = "Unknown...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template