标签 操作系统 下的文章

PHP获取访客操作系统名称的方法


分享一个PHP获得访客操作系统名称的方法,可以得到的操作系统有Windows 7、Windows XP (SP2)、Windows XP 64-bit Edition、Windows 2003、Windows Vista、Windows 2000、Windows ME、Windows NT 4.0、Windows 98、Windows 95、Mac、Linux、Unix、FreeBSD、SunOS、BeOS、OS/2、Macintosh、AIX、IBM OS/2、BSD、NetBSD。没有在这些在内的就以其他操作系统标注。如果是实际使用中用不到这么细,可以自行删除某些elseif,如果还有其他型号的就自行获得User_agent然后分析添加elseif。

function getUserOS(){  
	$user_OSagent = $_SERVER['HTTP_USER_AGENT'];  
	if(strpos($user_OSagent,"NT 6.1")){  
		$os_name ="Windows 7";   
	} elseif(strpos($user_OSagent,"NT 5.1")) {   
		$os_name ="Windows XP (SP2)";   
	} elseif(strpos($user_OSagent,"NT 5.2") && strpos($user_OSagent,"WOW64")){   
		$os_name ="Windows XP 64-bit Edition";   
	} elseif(strpos($user_OSagent,"NT 5.2")) {  
		$os_name ="Windows 2003";   
	} elseif(strpos($user_OSagent,"NT 6.0")) {  
		$os_name ="Windows Vista";   
	} elseif(strpos($user_OSagent,"NT 5.0")) {  
		$os_name ="Windows 2000";   
	} elseif(strpos($user_OSagent,"4.9")) {  
		$os_name ="Windows ME";  
	} elseif(strpos($user_OSagent,"NT 4")) {  
		$os_name ="Windows NT 4.0";  
	} elseif(strpos($user_OSagent,"98")) {  
		$os_name ="Windows 98";  
	} elseif(strpos($user_OSagent,"95")) {  
		$os_name ="Windows 95";  
	}elseif(strpos($user_OSagent,"NT")) {  
		$os_name ="Windows 较高版本";  
	}elseif(strpos($user_OSagent,"Mac")) {  
		$os_name ="Mac";  
	} elseif(strpos($user_OSagent,"Linux")) {   
		$os_name ="Linux";  
	} elseif(strpos($user_OSagent,"Unix")) {  
		$os_name ="Unix";  
	} elseif(strpos($user_OSagent,"FreeBSD")) {  
		$os_name ="FreeBSD";  
	} elseif(strpos($user_OSagent,"SunOS")) {  
		$os_name ="SunOS";   
	} elseif(strpos($user_OSagent,"BeOS")) {  
		$os_name ="BeOS";   
	} elseif(strpos($user_OSagent,"OS/2")) {  
		$os_name ="OS/2";  
	} elseif(strpos($user_OSagent,"PC")) {  
		$os_name ="Macintosh";  
	} elseif(strpos($user_OSagent,"AIX")) {  
		$os_name ="AIX";  
	} elseif(strpos($user_OSagent,"IBM OS/2")) {  
		$os_name ="IBM OS/2";  
	} elseif(strpos($user_OSagent,"BSD")) {  
		$os_name ="BSD";  
	} elseif(strpos($user_OSagent,"NetBSD")) {  
		$os_name ="NetBSD";  
	} else {  
		$os_name ="其它操作系统";  
	}  
	return $os_name;   
}