/ Published in: PHP
Detect and echo browser version including differentiating between Chrome and Safari.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php class Browser { "Name" => "unknown", "Agent" => "unknown") ; public function __Construct() { "mozilla", "seamonkey", "konqueror", "netscape", "gecko", "navigator", "mosaic", "lynx", "amaya", "omniweb", "avant", "camino", "flock", "aol"); foreach($browsers as $browser) { { $this->Name = $match[1] ; $this->Version = $match[2] ; break ; } } } public function __Get($name) { { } return $this->props[$name] ; } public function __Set($name, $val) { { SimpleError("No such property or function.", "Failed to set $name", $this->props) ; die ; } $this->props[$name] = $val ; } } $Browser = new Browser; ?> <?php //usage echo "$Browser->Name $Browser->Version" ; ?>