How do I get the current operating system type using PHP? Strictly speaking there are two kinds of cases , one is to get the server-side operating system type, one is to obtain the client's operating system type. The following authors will share some of the types of operating systems that are used in PHP to obtain these two scenarios.
(1) PHP access to server-side operating system type
You can use the constant Php_os or the system function php_uname (' s ')from the PHP system at this time. There are several things that may be true about the values that are returned by both:
- cygwin_nt-5.1
- Darwin
- Freebsd
- HP-UX
- IRIX64
- Linux
- NetBSD
- Openbsd
- SunOS
- Unix
- WIN32
- WINNT
- Windows
- cygwin_nt-5.1
- IRIX64
- SunOS
- HP-UX
- Openbsd
However, depending on the circumstances of the reader or print out the results to see the best, perhaps the results are not in the above list.
(2) PHP to obtain the client 's operating system type, here to share a function, more than the online spread of those judgments more accurate, and no bugs, the function code is as follows:
function Getos () {$os = ';
$Agent =$_server[' http_user_agent '];
if (eregi (' win ', $Agent) &&strpos ($Agent, ')} {$os = ' Windows 95 ';
}elseif (Eregi (' Win 9x ', $Agent) &&strpos ($Agent, ' 4.90 ')) {$os = ' Windows ME ';
}elseif (' Win ', $Agent) &&ereg (' Eregi ', $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 (' Win ', $Agent) &&ereg (' Eregi ', $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; }
Depending on the server side or the client to decide on the approach, hopefully through this article you know how to use PHP to get the current operating system type.