Home  >  Article  >  Backend Development  >  How to use PHP to determine the type of server operating system_PHP tutorial

How to use PHP to determine the type of server operating system_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:04:491184browse

I use winXP for local development, but the uploaded server is Linux. I always have to change the configuration file before uploading, and other things.
Now I decide what to execute by judging the type of the current server. program, then how does PHP determine what type of server it is on?
PHP has many system predefined variables. By judging them, you can easily determine whether the system is windows or *unix
The relevant functions or predefined variables are as follows

Copy code The code is as follows:

php_uname();
PHP_OS
DIRECTORY_SEPARATOR
PHP_SHLIB_SUFFIX
PATH_SEPARATOR

Specific procedure:
Copy code The code is as follows:

if(PATH_SEPARATOR==':') echo 'Linux';
else echo 'Windows';
?>

or
Copy code The code is as follows:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327738.htmlTechArticleI use winXP for local development, but the upload server is linux, and I always need to change it before uploading. Take a look at the configuration file, and other things. Now by judging the class of the current server...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn