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! ';
}
?>