Created
April 19, 2015 06:10
-
-
Save RyoSugimoto/2a714b83c96095bd3eda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserAgent{ | |
private $ua; | |
private $device; | |
public function set(){ | |
$this->ua = mb_strtolower($_SERVER['HTTP_USER_AGENT']); | |
if(strpos($this->ua,'iphone') !== false){ | |
$this->device = 'mobile'; | |
}elseif(strpos($this->ua,'ipod') !== false){ | |
$this->device = 'mobile'; | |
}elseif((strpos($this->ua,'android') !== false) && (strpos($this->ua, 'mobile') !== false)){ | |
$this->device = 'mobile'; | |
}elseif((strpos($this->ua,'windows') !== false) && (strpos($this->ua, 'phone') !== false)){ | |
$this->device = 'mobile'; | |
}elseif((strpos($this->ua,'firefox') !== false) && (strpos($this->ua, 'mobile') !== false)){ | |
$this->device = 'mobile'; | |
}elseif(strpos($this->ua,'blackberry') !== false){ | |
$this->device = 'mobile'; | |
}elseif(strpos($this->ua,'ipad') !== false){ | |
$this->device = 'tablet'; | |
}elseif((strpos($this->ua,'windows') !== false) && (strpos($this->ua, 'touch') !== false)){ | |
$this->device = 'tablet'; | |
}elseif((strpos($this->ua,'android') !== false) && (strpos($this->ua, 'mobile') === false)){ | |
$this->device = 'tablet'; | |
}elseif((strpos($this->ua,'firefox') !== false) && (strpos($this->ua, 'tablet') !== false)){ | |
$this->device = 'tablet'; | |
}elseif((strpos($this->ua,'kindle') !== false) || (strpos($this->ua, 'silk') !== false)){ | |
$this->device = 'tablet'; | |
}elseif((strpos($this->ua,'playbook') !== false)){ | |
$this->device = 'tablet'; | |
}else{ | |
$this->device = 'others'; | |
} | |
return $this->device; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment