1 <?php 2 function isMobile(){ 3 $useragent = isset($_SERVER['HTTP_USER_AGENT'])? $_SERVER['HTTP_USER_AGENT']: ''; 4 $mobile_list = array('Google Wireless Transcoder','Windows CE','WindowsCE', 5 'Symbian', 'Android','armv6l','armv5','Mobile','CentOS','mowser', 6 'AvantGo','Opera Mobi','J2ME/MIDP', 7 'Smartphone','Go.Web','Palm','iPAQ', 8 'Profile/MIDP', 'Configuration/CLDC-', 9 '160×160','176×220','240×240','240×320','320×240', 10 'UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson', 11 'Nokia','BlackBerry','Vodafone', 12 'BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH', 13 'Wapaka','DoCoMo','iPhone','iPod' 14 ); 15 foreach($mobile_list as $keyword){ 16 if(false !== strpos($useragent, $keyword)){ 17 return true; 18 } 19 } 20 return false; 21 } 22 echo isMobile()? 'mobile': 'pc';