How to detect mobile browser in php
/*******************************************************************************
* check mobile browser
*******************************************************************************/
function checkmobile(){
global $_SERVER;
if(isset($_SERVER["HTTP_X_WAP_PROFILE"])) return true;
if(preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) return true;
if(isset($_SERVER["HTTP_USER_AGENT"]))
{$uamatches = array("midp", "j2me", "avant", "docomo", "novarra", "palmos", "palmsource",
"240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry",
"mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm",
"up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu",
"sagem", "sony", "alcatel", "lg", "eric", "vx", "NEC", "philips",
"mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover",
"pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird",
"compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh",
"gradi", "jb", "\d\d\di", "moto");
foreach($uamatches as $uastring){
if(preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"])) return true;
}
}
return false;
}
code from http://www.brainhandles.com/2007/10/15/detecting-mobile-browsers/
another way/function i found at http://www.andymoore.info/php-to-detect-mobile-phones/