PHP能获取客户端操作系统类型吗
1个回答
展开全部
<?php
class ClientGetObj{
function getOS(){
global $_SERVER;
$agent=$_SERVER["HTTP_USER_AGENT"];
$os=false;
if(eregi("win",$agent)&&strpos($agent,"95")){
$os="Windows 95";
}else if(eregi("win 9x",$agent)&&strpos($agent,"4.90")){
$os="Windows ME";
}else if(eregi("win",$agent)&&eregi('98',$agent)){
$os="Windows 98";
}else if(eregi("win",$agent)&&eregi('nt 5.1',$agent)){
$os="Windows XP";
}else if(eregi("win",$agent)&&eregi('nt 5',$agent)){
$os="Windows 2000";
}else if(eregi("win",$agent)&&eregi('nt',$agent)){
$os="Windows NT";
}else if(eregi("win",$agent)&&eregi('32',$agent)){
$os="Windows 32";
}else if(eregi("linux",$agent)){
$os="Linux";
}else if(eregi("unix",$agent)){
$os="Unix";
}else if(eregi("sun",$agent)&&eregi("os",$agent)){
$os="SunOS";
}else if(eregi("ibm",$agent)&&eregi("os",$agent)){
$os="IBM OS/2";
}else if(eregi("mac",$agent)&&eregi("pc",$agent)){
$os="Macintosh";
}else if(eregi("powerpc",$agent)){
$os="PowerPC";
}else if(eregi("aix",$agent)){
$os="AIX";
}else if(eregi("HPUX",$agent)){
$os="HPUX";
}else if(eregi("netbsd",$agent)){
$os="NetBSD";
}else if(eregi("bsd",$agent)){
$os="BSD";
}else if(eregi("OSF1",$agent)){
$os="OSF1";
}else if(eregi("IRIX",$agent)){
$os="IRIX";
}else if(eregi("FreeBSD",$agent)){
$os="FreeBSD";
}else if(eregi("teleport",$agent)){
$os="teleport";
}else if(eregi("flashget",$agent)){
$os="flashget";
}else if(eregi("webzip",$agent)){
$os="webzip";
}else if(eregi("offline",$agent)){
$os="offline";
}else{
$os="Unknown";
}
return $os;
}
}
/*测试:
$myos=new ClientGetObj;
$result=$myos->getOS();
echo "客户端操作系统为:".$result;
*/
?>
class ClientGetObj{
function getOS(){
global $_SERVER;
$agent=$_SERVER["HTTP_USER_AGENT"];
$os=false;
if(eregi("win",$agent)&&strpos($agent,"95")){
$os="Windows 95";
}else if(eregi("win 9x",$agent)&&strpos($agent,"4.90")){
$os="Windows ME";
}else if(eregi("win",$agent)&&eregi('98',$agent)){
$os="Windows 98";
}else if(eregi("win",$agent)&&eregi('nt 5.1',$agent)){
$os="Windows XP";
}else if(eregi("win",$agent)&&eregi('nt 5',$agent)){
$os="Windows 2000";
}else if(eregi("win",$agent)&&eregi('nt',$agent)){
$os="Windows NT";
}else if(eregi("win",$agent)&&eregi('32',$agent)){
$os="Windows 32";
}else if(eregi("linux",$agent)){
$os="Linux";
}else if(eregi("unix",$agent)){
$os="Unix";
}else if(eregi("sun",$agent)&&eregi("os",$agent)){
$os="SunOS";
}else if(eregi("ibm",$agent)&&eregi("os",$agent)){
$os="IBM OS/2";
}else if(eregi("mac",$agent)&&eregi("pc",$agent)){
$os="Macintosh";
}else if(eregi("powerpc",$agent)){
$os="PowerPC";
}else if(eregi("aix",$agent)){
$os="AIX";
}else if(eregi("HPUX",$agent)){
$os="HPUX";
}else if(eregi("netbsd",$agent)){
$os="NetBSD";
}else if(eregi("bsd",$agent)){
$os="BSD";
}else if(eregi("OSF1",$agent)){
$os="OSF1";
}else if(eregi("IRIX",$agent)){
$os="IRIX";
}else if(eregi("FreeBSD",$agent)){
$os="FreeBSD";
}else if(eregi("teleport",$agent)){
$os="teleport";
}else if(eregi("flashget",$agent)){
$os="flashget";
}else if(eregi("webzip",$agent)){
$os="webzip";
}else if(eregi("offline",$agent)){
$os="offline";
}else{
$os="Unknown";
}
return $os;
}
}
/*测试:
$myos=new ClientGetObj;
$result=$myos->getOS();
echo "客户端操作系统为:".$result;
*/
?>
参考资料: http://blog.csdn.net/yinyiniao/article/details/5009672
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询