Skip to content

Get server operating system in PHP

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';
}
}
Published inProgramming

4 Comments

    • 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.

Leave a Reply

Your email address will not be published. Required fields are marked *