php有许多系统预定义变量,通过判断他们可以简单的判断系统是 windows还是*unix, 其中相关的函数或者预定义变量如下:
php_uname();
PHP_OS
DIRECTORY_SEPARATOR
PHP_SHLIB_SUFFIX
PATH_SEPARATOR
具体程序:
Php代码
<?
if(PATH_SEPARATOR==':') echo 'Linux';
else echo 'Windows';
?>
<?
if(PATH_SEPARATOR==':') echo 'Linux';
else echo 'Windows';
?>
或者
Php代码
<?php
echo php_uname();
echo "<br>";
echo PHP_OS;
echo "<br>";
/* 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!';
}
?>