How to Use php to determine the type of the server operating system

Source: Internet
Author: User

I use winXP for local development, but the uploaded server is linux. I always need to change the configuration file before each upload, and there are other things,
Now, by determining the type of the current server to determine what program to execute, how does php determine the type of server?
Php has many predefined system variables. By judging whether the system is windows or * unix
The related functions or predefined variables are as follows:
Copy codeThe Code is as follows:
Php_uname ();
PHP_ OS
DIRECTORY_SEPARATOR
PHP_SHLIB_SUFFIX
PATH_SEPARATOR

Specific procedures:
Copy codeThe Code is as follows:
<?
If (PATH_SEPARATOR = ':') echo 'linux ';
Else echo 'windows ';
?>

Or
Copy codeThe Code is as follows:
<? Php
Echo php_uname ();
Echo PHP_ OS;
/* Some possible outputs:
Linux localhost 2.4.21-0.13mdk #1 Fri Mar 14 15:08:06 EST 2003 i686
Linux
FreeBSD localhost 3.2-RELEASE #15: Mon Dec 17 08:46:02 GMT 2001
FreeBSD
Windows NT XN1 5.1 build 2600
WINNT
*/
If (strtoupper (substr (PHP_ OS, 0, 3) === 'win '){
Echo 'this is a server using Windows! ';
} Else {
Echo 'this is a server not using Windows! ';
}
?>

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.