Firefox OS Detection Recipe

Hi, folks —

The next update to MobileESP will support detection of smartphones running the Firefox OS. In the meantime, here is the recipe if you need it post-haste.

Mozilla thankfully publishes their useragent string pattern on their developer web site. The general pattern for the useragent string is: “Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0”.

You’d think that we could just stop at looking for just instances of “firefox” and “mobile”, but unfortunately, that wouldn’t be enough. Their browser for Android meets that criteria, too. So you have to look for “firefox” AND “mobile” AND NOT “android”. So the detection function for PHP would look like this:

var $engineFirefox = 'firefox'; //A new global variable

function DetectFirefoxOsPhone()
{
   if ((stripos($this->useragent, $this->engineFirefox) > -1) &&
      (stripos($this->useragent, $this->mobile) > -1) && 
      (stripos($this->useragent, $this->deviceAndroid) < 0)) //and no index
      return $this->true; 
   else
      return $this->false; 
}

 

An update along these lines will be published soon for the main code libraries.

By the way, we’re still looking for the useragent strings for Sailfish OS and Ubuntu Mobile OS. Please let us know if you come across them!

Happy coding!

Anthony

 

Owner of the MobileESP project. For the latest source code downloads, visit: https://github.com/ahand/mobileesp

Posted in General, MobileESP APIs