Accurately determine the type of OS PHP is running on

浪子不回头ぞ 提交于 2019-12-04 11:46:00
mellowsoon

It's important to know that no non-Windows OS string is going to contain the text "win", and no non-OSX OS string is going to contain the word "darwin", and so on. Detecting the OS is easy.

$uname = strtolower(php_uname());
if (strpos($uname, "darwin") !== false) {
    // It's OSX
} else if (strpos($uname, "win") !== false) {
    // It's windows
} else if (strpos($uname, "linux") !== false) {
    // It's Linux
} else {
    // It's something your script won't run on
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!