2

Possible Duplicate:
How to get the OS on which PHP is running?

I need my script to be able to recognize whether it's being run on a Windows or on a Linux system so it can behave accordingly. How do I do that?

EDIT: I need a definite way of doing that, that has no risk of recognizing the wrong OS.

Community
  • 1
  • 1

6 Answers6

1

Have you looked at the php_uname() function?

http://us.php.net/manual/en/function.php-uname.php

kapa
  • 75,446
  • 20
  • 155
  • 173
Scott C Wilson
  • 17,826
  • 10
  • 57
  • 80
1

if (PHP_OS == 'Linux') echo 'Linux os!'

gnur
  • 4,612
  • 2
  • 21
  • 33
1

predefined constant: PHP_OS ........

kapa
  • 75,446
  • 20
  • 155
  • 173
dynamic
  • 45,586
  • 54
  • 150
  • 229
1

php_uname and/or the PHP_OS constant will tell you. See the examples here: http://www.php.net/manual/en/function.php-uname.php

deceze
  • 491,798
  • 79
  • 706
  • 853
0

Here is the second link if I google 'os php':

MadH
  • 1,488
  • 4
  • 21
  • 29
-2

Note that anything that comes from the browser to your code can be spoofed, so it's not 'definite'.

Grim...
  • 15,954
  • 7
  • 42
  • 60