Finding out the OS my PHP script is run on [duplicate]
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.
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
if (PHP_OS == 'Linux') echo 'Linux os!'
predefined constant: PHP_OS
........
Have you looked at the php_uname()
function?
http://us.php.net/manual/en/function.php-uname.php
Here is the second link if I google 'os php':
Note that anything that comes from the browser to your code can be spoofed, so it's not 'definite'.
精彩评论