时间:2021-07-01 10:21:17 帮助过:10人阅读
不过根据具体情况读者还是自行打印出来结果看看最好,也许获得的结果不在上述之列。
(2)php获取客户端的操作系统类型,这里分享一个函数,比网上流传的那些判断更加精准,而且没有bug,函数代码如下:
function getOS(){ $os=''; $Agent=$_SERVER['HTTP_USER_AGENT']; if (eregi('win',$Agent)&&strpos($Agent, '95')){ $os='Windows 95'; }elseif(eregi('win 9x',$Agent)&&strpos($Agent, '4.90')){ $os='Windows ME'; }elseif(eregi('win',$Agent)&&ereg('98',$Agent)){ $os='Windows 98'; }elseif(eregi('win',$Agent)&&eregi('nt 5.0',$Agent)){ $os='Windows 2000'; }elseif(eregi('win',$Agent)&&eregi('nt 6.0',$Agent)){ $os='Windows Vista'; }elseif(eregi('win',$Agent)&&eregi('nt 6.1',$Agent)){ $os='Windows 7'; }elseif(eregi('win',$Agent)&&eregi('nt 5.1',$Agent)){ $os='Windows XP'; }elseif(eregi('win',$Agent)&&eregi('nt',$Agent)){ $os='Windows NT'; }elseif(eregi('win',$Agent)&&ereg('32',$Agent)){ $os='Windows 32'; }elseif(eregi('linux',$Agent)){ $os='Linux'; }elseif(eregi('unix',$Agent)){ $os='Unix'; }else if(eregi('sun',$Agent)&&eregi('os',$Agent)){ $os='SunOS'; }elseif(eregi('ibm',$Agent)&&eregi('os',$Agent)){ $os='IBM OS/2'; }elseif(eregi('Mac',$Agent)&&eregi('PC',$Agent)){ $os='Macintosh'; }elseif(eregi('PowerPC',$Agent)){ $os='PowerPC'; }elseif(eregi('AIX',$Agent)){ $os='AIX'; }elseif(eregi('HPUX',$Agent)){ $os='HPUX'; }elseif(eregi('NetBSD',$Agent)){ $os='NetBSD'; }elseif(eregi('BSD',$Agent)){ $os='BSD'; }elseif(ereg('OSF1',$Agent)){ $os='OSF1'; }elseif(ereg('IRIX',$Agent)){ $os='IRIX'; }elseif(eregi('FreeBSD',$Agent)){ $os='FreeBSD'; }elseif($os==''){ $os='Unknown'; } return $os; }
根据服务器端还是客户端来决定采取的办法,希望通过这篇文章大家知道如何使用php获取当前操作系统类型。