Posted By

shodan_uk on 03/30/11


Tagged

mobile


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

nbegiter
damarev


Check useragent for mobile device


 / Published in: PHP
 

Adapted from CakePHP

  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  

You need to login to post a comment.