Skip to content

Getting the OS information

Display OS information: php_uname()

Display information about the operating system.

With php_uname() you can retrieve operating system information in a PHP script. The function has a parameter mode, that allows you to define which information you want returned:

  • s : operating system name;
  • n : the host name;
  • r : the release name;
  • v : the version info;
  • m : the machine name;
  • a : all information above.

You can use:

$operating_system = php_uname("s");

Or you can walk through all options available:

$options = [
"s" => "Operating System",
"n" => "Hostname",
"r" => "Release name",
"v" => "Version info",
"m" => "Machine Name",
"a" => "Full infos"
];
foreach ($options as $key => $title) {
echo $title . ": ". php_uname($key) . PHP_EOL;
}