探测设备系统

Javascript 探测客户设备的操作系统

var deviceAgent = navigator.userAgent.toLowerCase();
var isAndroid = deviceAgent.indexOf("android") > -1; //&& ua.indexOf("mobile");

var iOS = deviceAgent.match(/(iphone|ipod|ipad)/);

if (iOS) {
    document.write('iOS');
} else if(isAndroid) {
    document.write('android');
}else {
	document.write(navigator.platform);
}

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){
        //were an Android Phone -- do something here
}else if($AndroidTablet){
        //were an Android Phone -- do something here
}else if($webOS){
        //were a webOS device -- do something here
}else if($BlackBerry){
        //were a BlackBerry phone -- do something here
}else if($RimTablet){
        //were a RIM/BlackBerry Tablet -- do something here
}