visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
294 experts, 1172 registered users, 1625 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


The DDRK link is back online.
We got a one week service interruption, sorry.
(23-30/01/2010)

Languages :: PHP :: PHP on Linux and Windows


By: vijay_rangaraj U.S.A.  Date: 11/07/2003 00:00:00  English  Points: 100 Status: Answered
Quality : Excellent
I have a Dual Boot Computer(Linux and Windows), where I am using Apache Server on both OS. I need to find using PHP, the name of the Operating System I am running currently.

The idea is, that I have the HTML files on the same partition mounted as a FAT32 file system, which is common to both Linux and Windows. If I can know at runtime which OS I am running, then I can decide on which CGI (C Program) program to choose from.

Any help would be appreciated.

-- Vijay Rangaraj.
By: VGR Date: 11/07/2003 21:22:00 English  Type : Comment
look in the getenv() and environment variable. If "WINDIR" is set... It's the windows ;-))
By: VGR Date: 11/07/2003 21:22:00 English  Type : Answer
it's even $_SERVER['WINDIR']
By: argon256 Date: 11/07/2003 21:36:00 English  Type : Comment
I think that the best way to do this is to find out whether the windows or unix version of Apache is running.

You can do this by checking the environment variable $_ENV["SERVER_SOFTWARE"] - it's version dependent, but you'll get a string back containing either 'Apache/1.3.27 (Unix)' or 'Apache/1.3.14 (Win32)' or similar, depending on versions etc.

Check with the following:

<?php
if (strpos($_ENV["SERVER_SOFTWARE"],"Unix")!==FALSE) {
//unix is running - do something
} elseif (strpos($_ENV["SERVER_SOFTWARE"],"Win32")!==FALSE) {
//windows is running - do something
} else {
//something bad has happened - do something
}
?>

To check exactly what the versions of apache on your two different setups give back in this variable, just do:
<?php
phpinfo();
?>

Note that the function used to check for Unix/Win32 [strpos()] is case sensitive.

Hope that this helps.
By: vijay_rangaraj Date: 11/07/2003 22:35:00 English  Type : Comment
Thanks a lot for your response guys!

I also tried $_ENV["OS"] and it works.

Do register to be able to answer

 Add This Article To:
 del.icio.usDel.icio.us  diggDigg  googleGoogle  spurlSpurl
 blinkBlink  wongWong  simpySimpy  yahooY! MyWeb 
EContact
browser fav
page generated in 67.286010 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page