Check useragent for mobile device


/ Published in: PHP
Save to your folder(s)

Adapted from CakePHP


Copy this code and paste it in your HTML
  1. if (!defined('REQUEST_MOBILE_UA')) {
  2. define('REQUEST_MOBILE_UA', '(iPhone|Android|MIDP|AvantGo|BlackBerry|J2ME|Opera Mini|DoCoMo|NetFront|Nokia|PalmOS|PalmSource|portalmmm|Plucker|ReqwirelessWeb|SonyEricsson|Symbian|UP\.Browser|Windows CE|Xiino)');
  3. }
  4.  
  5. function isMobile() {
  6. preg_match('/' . REQUEST_MOBILE_UA . '/i', $_SERVER['HTTP_USER_AGENT'], $match);
  7. if (!empty($match)) {
  8. return true;
  9. }
  10. return false;
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.