I have a website with a full browser and jQuery Mobile interface and users can switch between the two. Their preference is stored in a cookie. By default the site serves the full version to visitors whitout a preference cookie, but to make it better for modern smartphone users I want their default to be JQM. So, I have this code in the constructor of my base controller class:
class BaseController
{
protected $mobile; // must be 0 or 1, cookies can't handle boolean 'false'
public function __construct()
{
if (isset($_COOKIE['mobile']))
{
$this->mobile = $_COOKIE['mobile'];
}
else
{
$this->mobile = $this->isSmartphoneWithCookies();
setcookie("mobile", $this->mobile, time() + 7776000, '/', ''); // 90 days
}
}
private function isSmartphoneWithCookies()
{
$SMARTPHONE_WITH_COOKIES = "android.+mobile|blackberry|ip(hone|od)|opera m(ob|in)i";
return preg_match("/$SMARTPHONE_WITH_COOKIES/i", $_SERVER['HTTP_USER_AGENT']) ? 1 : 0;
}
// the rest of my controller class....
}
Here I prefer speed to accuracy, so I am not looking for a slower, up-to-date lookup service as suggested here: Simple Smart Phone detection
Just a quick indication that the visitor has one of the current top smartphone/tablet browsers that support cookies and JQM.
Can someone suggest an improvement for my $SMARTPHONE_WITH_COOKIES? Or point me to a collection of UA signatures that fit my use case? Specifically, is it safe to have blackberry in the list? Am I overlooking a popular capable browser?