Showing posts with label PHP_OS. Show all posts
Showing posts with label PHP_OS. Show all posts

Thursday, May 25, 2017

PHP Script - detect whether running under Linux or Windows?

PHP script - detect whether running under Linux or Windows or other Operating System? I don't have so much knowledge but can overcome with some solution. "PHP_OS" will solve this issue. Below is function to check if OS is Windows or not:

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    echo 'Windows!';
} else {
    echo 'Other Than Windows!';
}

PHP_OS will output below list of Operating System, not full list but I think it's almost all.
  • CYGWIN_NT-5.1
  • Darwin
  • FreeBSD
  • HP-UX
  • IRIX64
  • Linux
  • NetBSD
  • OpenBSD
  • SunOS
  • Unix
  • WIN32
  • WINNT
  • Windows
You can see on Wikipedia for more information.