Home > Articles > Programming infos and tutorials > Linux or Windows server – this is here the question…

Now and then a PHP programmer needs to figure out, if a script runs on a Linux- or Windows server. Of course you can always consult phpinfo() and check the info in the first line next to ‘System’. But for the further processing in scripts the function phpinfo() is not the best candidate.

Happily PHP offers us at least 3 other possibilities to find out:

Possibility No.1:

echo PHP_OS;

A windows server will return here usually the value “WINNT”.

Possibility No.2:

echo php_uname(‘s’);

With a Windows-Server we get a result like “Windows NT”. You could use this then in a strpos() query like here:

if (strpos($os_info,‘Windows’) !== FALSE){
    echo "YES, this is a windows box…";
 }


Possibility No.3:

echo DIRECTORY_SEPARATOR;

PHP provides for us a constant for the separator used in directories of the server. Windows systems as we know use the separator \ . So you could use this again for a PHP query with the function strpos() :

if (strpos(DIRECTORY_SEPARATOR != ‘/’){
    echo "Again! A windows server";
 }



—-
….I’m quite that these possibilities are not the only ones – further possibilities are very much appreciated :-)




Choose the way you would like to be notified for latest posts.

Subscribe to the RSS feed Sign up for Email alerts Follow on Twitter

No Comments yet

Be the first to write a comment

Leave a Comment