摘要:
下文讲述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.