The example in this article describes the browser checking class for PHP implementations. Share to everyone for your reference, specific as follows:
<?php//Original Author: epsilon7//sonymusic ([Email]sonymusic@163.net[/email]) class Browserdetector {var $UA = ""; The content of $HTTP _user_agent var $BROWSER = "Unknown"; Browser type var $PLATFORM = "Unknown"; Operating system var $VERSION = ""; Browser version number var $MAJORVER = ""; The browser main version number var $MINORVER = "";
Browser pair version number//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")) {$thi
S->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->bro
Wser = "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;
}}///test program starts $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> ";?>
More interested in PHP related content readers can view the site topics: "PHP file Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "Basic PHP Grammar Introduction Tutorial", "PHP operation Office Document skills Summary (including Word, Excel,access,ppt), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Tutorial", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.