How to find server operating system.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

How to find server operating system.

Post by daedalus__ »

i'm searching for a way to find the server operating system. I was having mild success regex'ing the $_SERVER['SERVER_SOFTWARE'] variable but I am so bad with regex that it didn't work in the end.

Perhaps someone could recommend a method?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
veridicus
Forum Commoner
Posts: 86
Joined: Fri Feb 23, 2007 9:16 am

Post by veridicus »

The $_ENV superglobal will give you every environment variable available to the script (based on the web server, OS, etc.). So if your web server runs on a UNIX-like OS run the "set" command at the prompt and check for a variable containing useful info. On my system it's MACHTYPE. Then try it in the script and see if it's available there. This is very platform-dependent, so you may need to check a few environment variables to cover any OS the script may run on.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

After digging around the manual I found what I needed, thanks guys!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And exactly what are you using now?
Post Reply