How do I get the current operating system type using PHP?
Strictly speaking there are two cases, one is to obtain 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 (not listed in Wikipedia)
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 the operating system type of the client
The function code is as follows:
$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 (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;}
The above is PHP to get the current operating system type of content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!