用PHP判断客户端是否是手机

时间:2022-08-10 08:41:08
 <?php
function isMobile(){
$useragent = isset($_SERVER['HTTP_USER_AGENT'])? $_SERVER['HTTP_USER_AGENT']: '';
$mobile_list = array('Google Wireless Transcoder','Windows CE','WindowsCE',
'Symbian', 'Android','armv6l','armv5','Mobile','CentOS','mowser',
'AvantGo','Opera Mobi','J2ME/MIDP',
'Smartphone','Go.Web','Palm','iPAQ',
'Profile/MIDP', 'Configuration/CLDC-',
'160×160','176×220','240×240','240×320','320×240',
'UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson',
'Nokia','BlackBerry','Vodafone',
'BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH',
'Wapaka','DoCoMo','iPhone','iPod'
);
foreach($mobile_list as $keyword){
if(false !== strpos($useragent, $keyword)){
return true;
}
}
return false;
}
echo isMobile()? 'mobile': 'pc';