There is a very useful predefined constant path_separator in PHP that we can use to determine whether the current server is Linux or Windows. This article will explain to you how PHP uses Path_separator to get the type of the current server.
Path_separator is a predefined constant in PHP, and we can directly echo this constant, in a Linux system, the constant output ":" In the Windows system, the constant output ";" Resolution Therefore, we can determine the current server system type by path_separator the output value.
Output results in Linux systems:
<?php
var_dump (path_separator);
Output Result: string (1) ":"
?>
To output results in a Windows system:
<?php
var_dump (path_separator);
Output Result: string (1) ";"
? >
Write a function that determines the current server system type:
function Getos () {
if (Path_separator = = ': ') {return
' Linux ';
} else{return
' Windows ';
}
How you need to determine the current server system type, you can call the above function directly.
Thank you for reading, I hope to help you, thank you for your support for this site!