Har haft samme udfordring på et tidspunkt. Fandt denne funktion. <?php class BrowserDetection { private $_user_agent; private $_name; private $_version; private $_platform;
function detect() { $this->detectBrowser(); $this->detectPlatform(); return $this; }
function detectBrowser() { foreach($this->_basic_browser as $pattern => $name) { if( preg_match("/".$pattern."/i",$this->_user_agent, $match)) { $this->_name = $name; // finally get the correct version number $known = array('Version', $pattern, 'other'); $pattern_version = '#(?<browser>' . join('|', $known).')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#'; if (!preg_match_all($pattern_version, $this->_user_agent, $matches)) { // we have no matching number just continue } // see how many we have $i = count($matches['browser']); if ($i != 1) { //we will have two since we are not using 'other' argument yet //see if version is before or after the name if (strripos($this->_user_agent,"Version") < strripos($this->_user_agent,$pattern)){ @$this->_version = $matches['version'][0]; } else { @$this->_version = $matches['version'][1]; } } else { $this->_version = $matches['version'][0]; } break; } } }
function detectPlatform() { foreach($this->_basic_platform as $key => $platform) { if (stripos($this->_user_agent, $key) !== false) { $this->_platform = $platform; break; } } }
function getBrowser() { if(!empty($this->_name)) { return $this->_name; } }
function getVersion() { return $this->_version; }
function getPlatform() { if(!empty($this->_platform)) { return $this->_platform; } }
function getUserAgent() { return $this->_user_agent; }
Super tak - den vil jeg lige prøve at se nærmere på og teste :)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.