Browser check class implemented by PHP, browser implemented by php
This example describes the browser check class implemented by PHP. We will share this with you for your reference. The details are as follows:
<? Php // Original Author: epsilon7 // SonyMusic ([email] sonymusic@163.net [/email]) class BrowserDetector {var $ UA = ""; // $ HTTP_USER_AGENT content var $ BROWSER = "Unknown"; // BROWSER type var $ PLATFORM = "Unknown"; // operating system var $ VERSION = ""; // browser version var $ MAJORVER = ""; // main browser version var $ MINORVER = ""; // browser minor version/* constructor start */function BrowserDetector () {$ this-> UA = getenv (HTTP_USER_AGENT); $ preparens = ""; $ parens = ""; $ I = strpos ($ thi S-> 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;} elsei F (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, s Trlen ($ 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, strl En ("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);} else {$ this-> VERSION = $ leftover ;} $ j = strpos ($ this-> VERSION ,". "); if ($ j >=0) {$ this-> MAJORVER = substr ($ this-> VERSION, 0, $ j ); $ this-> MINORVER = substr ($ this-> VERSION, $ J + 1, strlen ($ this-> VERSION);} else {$ this-> MAJORVER = $ this-> VERSION ;}}} // test the program $ test = new browserdetector; echo $ test-> UA. "<br>"; echo $ test-> BROWSER. "<br>"; echo $ test-> PLATFORM. "<br>"; echo $ test-> VERSION. "<br>"; echo $ test-> MAJORVER. "<br>"; echo $ test-> MINORVER. "<br>";?>