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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting server OS

Status
Not open for further replies.

c4n

Programmer
Mar 12, 2002
110
0
0
SI
Hello,

I need to detect server operating system within my PHP script, any ideas how to do it?

I need to classify server in one of the following categories:

- unix (linux)
- windows
- mac
- other

Any help apreachiated.

Thanks,

c4n
 
Far as server software goes not really much you can do other than reading the info at phpinfo() . Or you can use

Code:
 $_SERVER['SERVER_SOFTWARE']

this will for example, off my webhosting return

Code:
Apache/1.3.33 (Unix) mod_gzip/1.3.26.1a mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.3.9 FrontPage/5.0.2.2635 mod_ssl/2.8.22 OpenSSL/0.9.7a
*linux server generally more descriptive what they are running to PHP.

and on my windows box

Code:
Apache/1.3.31 (Win32) PHP/4.3.11-dev

There really isnt a surefire way to know what OS it's running on unless the webserver tells you ( in this case, apache has (unix) and (win32) ), you can more easily tell what your visitors are running by using.

Code:
$_SERVER['HTTP_USER_AGENT']

Which in my case returns

Code:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0 (ax)

Karl Blessing
PHP/MySQL Developer
 
Also its possible to use $_ENV["TERM"] , which on my hosting returns "Linux" but that variables not even aval on the windows box.

But chances are you are the only one that'll need to know your server, and just looking at the results returned by phpinfo() is more than enough.

Karl Blessing
PHP/MySQL Developer
 
Hello,

Thanks for the replies. I am using $_SERVER['SERVER_SOFTWARE'] at the moment, just thought I'd ask if there is a better way...

If anyone knows any other way please let me know.

Regards,

c4n
 
try

Code:
<?php
$os = PHP_OS;
echo $os;
?>

Which on linus gives Linux and on XP WINNT (oddly !). No idea what mac or anything else gives you
 
Hello and sorry for the late reply. I didn't know about the PHP_OS thing, thanks! Looks nice, will test it on different servers and probably be able to use it.

Thanks again!

Regards

c4n
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top