This function returns ‘win’ if running on a Windows server and ‘linux’ if not running on a Windows server. It should be pretty easy to extend it to match other server operating systems, but this is all I needed.
function operating_system() /* Returns 'win' for a Windows server, 'linux' for others */ { $os_string = php_uname('s'); if (strpos(strtoupper($os_string), 'WIN')!==false) { return 'win'; } else { return 'linux'; } }
Thanks alot.
Cheers, just what I needed for my CMS installation script. I wasn’t aware of the php_uname() function.
You can also find the server OS with the constant PHP_OS or DIRECTORY_SEPARATOR.
I think that PHP fills in the PHP_OS constant using uname, so you’re right, it probably makes more sense to use that constant since it’s already been run once.