One browser check class

Source: Internet
Author: User
Tags strtok
Original Author: epsilon7SonyMusic (sonymusic@163.net) classBrowserDetector {var $ UA & quot; $ HTTP_USER_AGENT content var $ BROWSER & quot; Unknown & quot ;; browser type var $ PLATFORM // 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
Var $ MAJORVER = ""; // Main browser version
Var $ MINORVER = ""; // the minor version number of the browser
/* Start the 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;
}
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;
}
}
}

// Start the test program
$ 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.