6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
7 * @version SVN: $Id: Mobile_Detect.php 3 2009-05-21 13:06:28Z vic.stanciu $
11 * MODIFIED FOR THE JAPPIX PROJECT
12 * Last revision: 20/11/10
14 * Thanks to LinkMauve for his patch!
22 protected $isMobile = false;
23 protected $isAndroid = null;
24 protected $isIphone = null;
25 protected $isBlackberry = null;
26 protected $isOpera = null;
27 protected $isPalm = null;
28 protected $isWindows = null;
29 protected $isGeneric = null;
31 protected $devices = array(
32 "android" => "android",
33 "blackberry" => "blackberry",
34 "iphone" => "(iphone|ipod)",
35 "opera" => "opera mini",
36 "palm" => "(avantgo|blazer|elaine|hiptop|palm|plucker|xiino)",
37 "windows" => "windows ce; (iemobile|ppc|smartphone)",
38 "generic" => "(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap)"
42 public function __construct() {
43 $this->userAgent = $_SERVER['HTTP_USER_AGENT'];
45 if (isset($_SERVER['HTTP_ACCEPT']))
46 $this->accept = $_SERVER['HTTP_ACCEPT'];
50 if (isset($_SERVER['HTTP_X_WAP_PROFILE'])|| isset($_SERVER['HTTP_PROFILE'])) {
51 $this->isMobile = true;
52 } elseif (strpos($this->accept,'text/vnd.wap.wml') > 0 || strpos($this->accept,'application/vnd.wap.xhtml+xml') > 0) {
53 $this->isMobile = true;
55 foreach ($this->devices as $device => $regexp) {
56 if ($this->isDevice($device)) {
57 $this->isMobile = true;
65 * Overloads isAndroid() | isBlackberry() | isOpera() | isPalm() | isWindows() | isGeneric() through isDevice()
68 * @param array $arguments
71 public function __call($name, $arguments) {
72 $device = substr($name, 2);
73 if ($name == "is" . ucfirst($device)) {
74 return $this->isDevice($device);
76 trigger_error("Method $name not defined", E_USER_ERROR);
82 * Returns true if any type of mobile device detected, including special ones
85 public function isMobile() {
86 return $this->isMobile;
90 protected function isDevice($device) {
91 $var = "is" . ucfirst($device);
92 $return = $this->$var === null ? (bool) preg_match("/" . $this->devices[$device] . "/i", $this->userAgent) : $this->$var;
94 if ($device != 'generic' && $return == true) {
95 $this->isGeneric = false;