PHP browser check class, php browser _ PHP Tutorial

Source: Internet
Author: User
Tags strtok
PHP implements browser inspection. PHP browser check class. php browser this article describes the browser check class implemented by PHP. For your reference, we will share with you the following: php author: browser check class implemented by epsilon7 PHP, php browser implementation

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 ($ 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);} 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 ;}}// the test program starts $ test = new browserdetector; echo $ test-> UA."
"; Echo $ test-> BROWSER ."
"; Echo $ test-> PLATFORM ."
"; Echo $ test-> VERSION ."
"; Echo $ test-> MAJORVER ."
"; Echo $ test-> MINORVER ."
";?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.