Php judges the current operating system type, php judges the current _ PHP Tutorial

Source: Internet
Author: User
Tags ereg
Php determines the current operating system type, and php determines the current. Php determines the current operating system type. php determines how to use php to obtain the current operating system type? Strictly speaking, there are two situations: one is to obtain the server-side operation php to determine the current operating system type, and the other is to determine the current

How can I use php to obtain the current operating system type? Strictly speaking, hereTwo casesOne is to obtain the operating system type of the server, and the other is to obtain the operating system type of the client. The authors will share with you how to use php to obtain the operating system types in these two cases.
(1) php obtains the operating system type of the server.
In this case, you can use the built-in php SystemConstant PHP_ OSOr system functionsPhp_uname ('s ').The possible values returned by the two methods are as follows:

  • 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, based on the actual situation, the reader still prints out the results to see the best results. The results may not be listed above.
(2) php obtains the operating system type of the client. Here we share a function, which is more accurate than the judgments circulating on the Internet and has no bugs. the Function code is as follows:

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; } 

The method is determined based on the server side or the client side. I hope you will know how to use php to obtain the current operating system type through this article.

How can I use php to obtain the current operating system type? Strictly speaking, there are two cases: one is to obtain the server operation...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.