1

How can I check in a PHP script if it's running in a windows or Unix environment?

tshepang
  • 12,111
  • 21
  • 91
  • 136
John
  • 1,059
  • 4
  • 12
  • 16

5 Answers5

3

check the variable PHP_OS

McAden
  • 13,714
  • 5
  • 37
  • 63
2

Here's what I'm using:

if(PHP_SHLIB_SUFFIX == 'so')// *nix (aka NOT windows)
{
    // Blah
}
else // Windows
{
    // Blah again
}

It's simple and you don't need to wade through the massive number of options of things like PHP_OS

Community
  • 1
  • 1
Blair McMillan
  • 5,299
  • 2
  • 25
  • 45
1
if (PHP_OS == 'WINNT')
{
   echo "Do windows stuff";
}
Garrows
  • 3,031
  • 3
  • 25
  • 21
1

PHP_OS as mentioned above for a simple variable.

See also: php_uname() For a longer answer.

jjclarkson
  • 5,890
  • 6
  • 40
  • 62
0

I believe this information is available in the $_SERVER variable as follows:

$_SERVER['SERVER_SOFTWARE']
Kaleb Brasee
  • 51,193
  • 8
  • 108
  • 113