siliconpi siliconpi - 2 years ago 129
Linux Question

PHP script - detect whether running under linux or Windows?

I have a PHP script that may be placed on a windows system or a linux system. I need to run different commands in either case.

how can i detect which environment i am in? (preferably something php rather than clever system hacks)

sorry sorry!! the script is running from the command line!!!!

Answer Source

Check the value of the PHP_OS constantDocs.

It will give you various values on Windows like WIN32, WINNT or Windows.

See as well: Possible Values For: PHP_OS and php_unameDocs:

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    echo 'This is a server using Windows!';
} else {
    echo 'This is a server not using Windows!';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download