The following PHP function is used to detect mobile device: ipod, iphone, blackberry and android
, if from mobile device, the function will return true.
function is_mobile_device() {
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
return ((stripos($agent, 'ipod') !== false && stripos($agent, 'ipod') >= 0) ||
(stripos($agent, 'iphone') !== false && stripos($agent, 'iphone') >= 0) ||
(stripos($agent, 'blackberry') !== false && stripos($agent, 'blackberry') >= 0) ||
(stripos($agent, 'android') !== false && stripos($agent, 'android') >= 0))
? true : false;
}
Note: _SERVER['HTTP_USER_AGENT'] is used to retrieve information about the users browser, computer operating system and mobile type.
stripos — Find the position of the first occurrence of a case-insensitive substring in a string.
Returns
Returns
FALSE
if the needle was not found.
No comments:
Post a Comment