php判断当前操作系统类型_php技巧
如何使用php获取当前操作系统类型呢?严格来说这里分两种情况,一种情况是获取服务器端的操作系统类型,一种是获取客户端的操作系统类型。下面作者将对如何使用php获取这两种情况下的操作系统类型和大家做一些分享。
(1)php获取服务器端的操作系统类型
这个时候可以使用php系统自带的常量 PHP_OS 或者系统函数php_uname('s')。关于这两者返回的值可能的情况基本有如下几种情况:
- 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
不过根据具体情况读者还是自行打印出来结果看看最好,也许获得的结果不在上述之列。
(2)php获取客户端的操作系统类型,这里分享一个函数,比网上流传的那些判断更加精准,而且没有bug,函数代码如下:
function getOS(){ $os=''; $Agent=$_SERVER['HTTP_USER_AGENT']; if (eregi('win',$Agent)&&strpos($Agent, '95')){ $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('32',$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; }
根据服务器端还是客户端来决定采取的办法,希望通过这篇文章大家知道如何使用php获取当前操作系统类型。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Alipay PHP...
