Quick Search:
 
 PHP Code: Detect Mobile/WAP browser Jump to:  
Category: >> PHP Code >> Detect Mobile/WAP browser  

<< lastnext >>

Snippet Name: Detect Mobile/WAP browser

Description: This code will detect most Mobile/WAP browsers. Useful for serving up different content to mobile phones.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: February 27th, 2009

<?PHP
 
$mobile_browser = '0';
 
IF(PREG_MATCH('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i',
    STRTOLOWER($_SERVER['HTTP_USER_AGENT']))){
    $mobile_browser++;
    }
 
IF((STRPOS(STRTOLOWER($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or
    ((ISSET($_SERVER['HTTP_X_WAP_PROFILE']) or ISSET($_SERVER['HTTP_PROFILE'])))){
    $mobile_browser++;
    }
 
$mobile_ua = STRTOLOWER(SUBSTR($_SERVER['HTTP_USER_AGENT'],0,4));
$mobile_agents = ARRAY(
    'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
    'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
    'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
    'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
    'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
    'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
    'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
    'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
    'wapr','webc','winw','winw','xda','xda-');
 
IF(IN_ARRAY($mobile_ua,$mobile_agents)){
    $mobile_browser++;
    }
IF (STRPOS(STRTOLOWER($_SERVER['ALL_HTTP']),'OperaMini')>0) {
    $mobile_browser++;
    }
IF (STRPOS(STRTOLOWER($_SERVER['HTTP_USER_AGENT']),'windows')>0) {
    $mobile_browser=0;
    }
 
 
IF($mobile_browser>0){
   // do something
   } ELSE {
   // do something else
   }
 
 
?>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org