php获取服务器系统,php如何获取服务器的操作系统呢?

摘要:

下文讲述PHP中获取服务器操作系统的方法分享,如下所示;

在php开发中,我们经常需获取操作系统信息,

然后根据不同的操作系统,执行不同的计算,

那么如何获取操作系统的版本呢?

下文将一一道来,如下所示:

实现思路:

使用 $_SERVER['HTTP_USER_AGENT']

即可获取操作系统的相关信息

例:

php 获取操作系统的示例分享

function getSystem() {

$agent = $_SERVER['HTTP_USER_AGENT'];

$os = false;

if (stristr($agent,'win')) {

$os = 'Windows';

}

else if (stristr($agent,'win') && stristr($agent, '95')) {

$os = 'Windows 95';

}

else if (stristr($agent,'win 9x') && stristr($agent, '4.90')) {

$os = 'Windows ME';

}

else if (stristr($agent,'win') && stristr($agent,'98')) {

$os = 'Windows 98';

}

else if (stristr($agent,'win') && stristr($agent,'nt 5.1')) {

$os = 'Windows XP';

}

else if (stristr($agent,'win') && stristr($agent,'nt 5')) {

$os = 'Windows 2000';

}

else if (stristr($agent,'win') && stristr($agent,'nt')) {

$os = 'Windows NT';

}

else if (stristr($agent,'win') && stristr($agent,'32')) {

$os = 'Windows 32';

} else if (stristr($agent,'linux')) {

$os = 'Linux';

}

else if (stristr($agent,'unix')) {

$os = 'Unix';

}

else if (stristr($agent,'sun') && stristr($agent,'os')) {

$os = 'SunOS';

}

else if (stristr($agent,'ibm') && stristr($agent,'os')) {

$os = 'IBM OS/2';

}

else if (stristr($agent,'Mac')) {

$os = 'Mac OS X';

}

else if (stristr($agent,'PowerPC')) {

$os = 'PowerPC';

}

else if (stristr($agent,'AIX')) {

$os = 'AIX';

}

else if (stristr($agent,'HPUX')) {

$os = 'HPUX';

}

else if (stristr($agent,'NetBSD')) {

$os = 'NetBSD';

}

else if (stristr($agent,'BSD')) {

$os = 'BSD';

}

else if (stristr($agent,'OSF1')) {

$os = 'OSF1';

}

else if (stristr($agent,'IRIX')) {

$os = 'IRIX';

}

else if (stristr($agent,'FreeBSD')) {

$os = 'FreeBSD';

}

else if (stristr($agent,'teleport')) {

$os = 'teleport';

}

else if (stristr($agent,'flashget')) {

$os = 'flashget';

}

else if (stristr($agent,'webzip')) {

$os = 'webzip';

}

else if (stristr($agent,'offline')) {

$os = 'offline';

}

else{

$os = 'Unknown';

}

return $os;

}

No related posts.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值