Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you detect the server's OS? 1

Status
Not open for further replies.

thenewa2x

Programmer
Dec 10, 2002
349
US
How would I detect the OS that the script is currently running on? Not the client's but the server's. I want the method of checking to be cross-platform compatible.

---------------------------------------
TINSTAAFL, which is why I contribute.
 
I just ran it on my Windows desktop and it did not work. The array key doesn't even exist. Does it only exist when you have a web server (like Apache or IIS) running? I need something constant.

---------------------------------------
TINSTAAFL, which is why I contribute.
 
what web server are you using on your desktop?

or are you saying you ran it from the command line?
 
Maybe this is stating the obvious, but the variable jpadie gave you is a PHP variable - you have to be running a PHP interpreter to interpret PHP, and PHP interpreters run with web servers. Or perhaps we don't understand what you meant...
 
I am running PHP 5.1+ on both my server and desktop. My desktop does not have a web server installed. My server does. I was just wondering if the variable's name is consistent and not something PHP grabs from what the operation system or web server provides in the environment variables. I'm looking for consistency in the server information.

---------------------------------------
TINSTAAFL, which is why I contribute.
 
Okay, you're out of my league - I didn't know one could run PHP outside of an HTTP environment.

But what I can do to help is give you the value of that variable on all the types of systems I have access to. On my WinXP running Apache, it says:
Apache/1.3.20 (Win32) PHP/4.1.0
On one hoster's FreeBSD server, it says:
Apache/1.3.33 (Unix) PHP/4.3.10 FrontPage/5.0.2.2623
On a different hoster's Linux server, even though it is also running PHP, it simply says:
Apache/1.3.34 (Unix)
On yet another (yes, I deal with a lot of hosters!), it is quite verbose:
Apache/1.3.33 (Unix) mod_throttle/3.1.2 DAV/1.0.3 mod_fastcgi/2.4.2 mod_gzip/1.3.26.1a PHP/4.4.2 mod_ssl/2.8.22 OpenSSL/0.9.7e

Sorry, I have no Macs to try it on, but then again, does anyone use a Mac as a web server?

If you call phpinfo(), you will see a huge list of system variables and their values - I have found that very helpful when deciding what variables to use to get the information I need.
 
@osakawebbie
indeed you can run php on the command line. essentially this is what a cgi is. in fact there is a class of desktop applications that uses php as their interface with the OS (have a google for php gtk).

@thenewa2x
if php is called from a web server the $_SERVER['SERVER_SOFTWARE'] variable is populated.
if it is called from a commandline then the $_SERVER['OS'] variable is populated.

i believe one of these will always be populated which should make it possible for you to construct a cross-platform function to return what you want.

 
Sorry, I have no Macs to try it on, but then again, does anyone use a Mac as a web server?

As a matter of fact, I have one:

Code:
Apache/1.3.27 (Darwin) mod_ssl/2.8.12 OpenSSL/0.9.7b
 
Thank you all.

---------------------------------------
TINSTAAFL, which is why I contribute.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top