判斷裝置 PHP Mobile Device Detection
原文地址 : 簡單地用 PHP 判斷訪客的上網裝置 原文英文頁面
//Detect special conditions devices
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
if(stripos($_SERVER['HTTP_USER_AGENT'],"Android") && stripos($_SERVER['HTTP_USER_AGENT'],"mobile")){
$Android = true;
}else if(stripos($_SERVER['HTTP_USER_AGENT'],"Android")){
$Android = false;
$AndroidTablet = true;
}else{
$Android = false;
$AndroidTablet = false;
}
$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
$BlackBerry = stripos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$RimTablet= stripos($_SERVER['HTTP_USER_AGENT'],"RIM Tablet");
//do something with this information
if( $iPod || $iPhone ){
//were an iPhone/iPod touch -- do something here
}else if($iPad){
//were an iPad -- do something here
}else if($Android){
//we're an Android Phone -- do something here
}else if($AndroidTablet){
//we're an Android Phone -- do something here
}else if($webOS){
//we're a webOS device -- do something here
}else if($BlackBerry){
//we're a BlackBerry phone -- do something here
}else if($RimTablet){
//we're a RIM/BlackBerry Tablet -- do something here
}else{
//we're not a mobile device.
}
更詳細的說明針對 PHP JS jQuery JSP
http://ithelp.ithome.com.tw/articles/10095184
或用這一包
參考
if(!isset($_SESSION['viewmode'])){
$iPod = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
if(stripos($_SERVER['HTTP_USER_AGENT'],"Android") && stripos($_SERVER['HTTP_USER_AGENT'],"mobile")){
$Android = true;
}else if(stripos($_SERVER['HTTP_USER_AGENT'],"Android")){
$Android = false;
$AndroidTablet = true;
}else{
$Android = false;
$AndroidTablet = false;
}
$webOS = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
$BlackBerry = stripos($_SERVER['HTTP_USER_AGENT'],"BlackBerry");
$RimTablet= stripos($_SERVER['HTTP_USER_AGENT'],"RIM Tablet");
//do something with this information
if( $iPod || $iPhone ||$Android){
$viewmode = "mobile";$vm_icon = "<i class=\"ion-iphone\"></i>";
}else if($iPad ||$AndroidTablet){
$viewmode = "mobile";$vm_icon = "<i class=\"ion-iphone\"></i>";
}else if($webOS){
$viewmode = "webos";
}else{
$viewmode = "pc";$vm_icon = "<i class=\"ion-monitor\"></i>";
}
$_SESSION['viewmode'] = $viewmode;
}
if($_SESSION['viewmode']=="pc"){
$popup = 'width=600&height=600';
}else{$popup = 'width=100%&height=100%';}