PHP to know operating system

To design with portability in mind, you may want to first test for the platform on which the script is running. PHP defines the constant PHP_OS, which contains the name of the operating system on which the PHP parser is executing. Possible values for the PHP_OS constant include “HP-UX”, “Darwin” (Mac OS), “Linux”, “SunOS”, “WIN32”, and “WINNT”. You may also want to consider the php_uname() built-in function; it returns even more operating system information

The following code shows how to test for a Windows platform:

if (PHP_OS == 'WIN32' || PHP_OS == 'WINNT') {
 echo "You are on a Windows System";
else {
 // some other platform
 echo "You are NOT on a Windows System";

Leave a Comment