bobbfwed Posted November 4, 2008 Share Posted November 4, 2008 This must have come up before, but the search function on these (and every other forum system) is impossible to get results out of...anyway... I am trying to find the surest way to get the server's operating system. All I need is "Windows"/"Linux"/"Mac"/etc. I don't need versions or whatnot. I see some of that info entrenched in $_SERVER ... but I was wondering if there is a simpler way. Also...while we are at it. I have a function that changes a file's or directory's permissions with chmod. But on windows the chmod of a directory seems to do very little. There are two settings: 0777 and 0555 (read-only). 0555 still allows you to rename the directory and create files/dirs inside of it. Files have only two options as well: 0666 and 0444 (read-only). Is there any way to beef it up? So to relate to the server OS question: I will probably just do what windows does, only give you the read-only/everything options when on Windows, and give full octal control when on other operating systems (I'm assuming Mac -- at least MacX -- uses the Unix/Linux octal system?). Quote Link to comment https://forums.phpfreaks.com/topic/131419-solved-operating-system-check/ Share on other sites More sharing options...
.josh Posted November 4, 2008 Share Posted November 4, 2008 So...what's wrong with using echo $_SERVER['SERVER_SOFTWARE']; ? I don't think you're going to find any kind of environment variable or global that simple says "Windows"/"Linux"/"Mac"/etc... your best bet is to just use ^ and use some regex to parse it. Quote Link to comment https://forums.phpfreaks.com/topic/131419-solved-operating-system-check/#findComment-682541 Share on other sites More sharing options...
bobbfwed Posted November 5, 2008 Author Share Posted November 5, 2008 well this is what I did while I was awaiting an answer... if (false !== stripos($_SERVER['SERVER_SOFTWARE'], 'win')) so... i guess that is the solution. I don't have access to a linux box at the moment. What would linux display in SERVER_SOFTWARE? Quote Link to comment https://forums.phpfreaks.com/topic/131419-solved-operating-system-check/#findComment-682549 Share on other sites More sharing options...
trq Posted November 5, 2008 Share Posted November 5, 2008 $_SERVER['SERVER_SOFTWARE'] returns the name of the webserver, not the OS. php_uname is what your after, either that or simply use the PHP_OS constant. Quote Link to comment https://forums.phpfreaks.com/topic/131419-solved-operating-system-check/#findComment-682553 Share on other sites More sharing options...
bobbfwed Posted November 5, 2008 Author Share Posted November 5, 2008 even better, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/131419-solved-operating-system-check/#findComment-682556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.