PHP determines the current operating system type, PHP determines the current
How do I get the current operating system type using PHP? Strictly speaking there are two cases , one case is to get the server-side operating system type, one is to obtain the client's operating system type. The following authors will do some sharing on how to use PHP to get the operating system type in both cases.
(1) PHP gets the server-side operating system type
This time you can use the PHP system's own constant php_os or system function php_uname (' s '). There are several scenarios in which the values returned by the two are possible:
- 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 their own results to see the best, perhaps the results are not listed above.
(2) php gets client 's operating system type, here to share a function, more accurate than those circulated on the Internet, and no bug, the function code is as follows:
function Getos () {$os = '; $Agent =$_server[' http_user_agent ']; if (' Win ', $Agent) &&strpos ($Agent, ' eregi ') {$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 (' + ', $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; }
According to the server side or the client to decide how to take, I hope this article you know how to use PHP to get the current operating system type.
http://www.bkjia.com/PHPjc/1065575.html www.bkjia.com true http://www.bkjia.com/PHPjc/1065575.html techarticle PHP determines the current operating system type, PHP to determine the current use of PHP to get the current operating system type? Strictly speaking there are two cases, one situation is to get server-side operations ...