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 ."
";
?>