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
  • 77,694
  • 21
  • 158
  • 175
Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83
1

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

gnur
  • 4,671
  • 2
  • 20
  • 33
1

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

kapa
  • 77,694
  • 21
  • 158
  • 175
dynamic
  • 46,985
  • 55
  • 154
  • 231
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
  • 510,633
  • 85
  • 743
  • 889
0

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

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

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

Grim...
  • 16,518
  • 7
  • 45
  • 61