PHP üzerinde çalıştığı OS almak nasıl?

4 Cevap php

Bir unix / dos özel komut dosyası oluşturmak için ben ben işletim sisteminin hangi tür bilmeniz gerekir.

How do i get this information?
phpinfo(); tells me a lot more and not very clear whether I'm running on unix or not.

4 Cevap

PHP sahip genellikle yararlı olduğu predefined constants çok.

Burada, PHP_OS aradığınız biridir.


For instance, on my current machine, this code :

var_dump(PHP_OS);

Verir:

string 'Linux' (length=5)


You have some examples and comparisons with what the php_uname function can get you on the
manual page of php_uname ; for instance (quoting) :

<?php
echo php_uname();
echo PHP_OS;

/* Some possible outputs:
Linux localhost 2.4.21-0.13mdk #1 Fri Mar 14 15:08:06 EST 2003 i686
Linux

FreeBSD localhost 3.2-RELEASE #15: Mon Dec 17 08:46:02 GMT 2001
FreeBSD

Windows NT XN1 5.1 build 2600
WINNT
*/

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    echo 'This is a server using Windows!';
} else {
    echo 'This is a server not using Windows!';
}

O sayfa da diyor ki:

For the name of just the operating system, consider using the PHP_OS constant, but keep in mind this constant will contain the operating system PHP was built on.

Sadece PHP_OS aslında PHP üzerine inşa edildiği platformu içeren aklınızda. Bu dağıtılmış olduğu olduğu gibi aynı platformu olmayabilir. Bu nedenle php_uname('s') daha güvenilirdir.

http://us2.php.net/manual/en/reserved.constants.php: PHP_OS konak os adıyla prefined edilir

Php üzerinde çalıştığı platformu kontrol etmek için 2 farklı yolu vardır.

1 - Bir const PHP_OS kullanarak ve php içinde inşa edilmiştir 'işletim sistemi adıyla' işaret eder.

2 - fonksiyonu php_uname (yerleşik php kullanarak) size platformu hakkında daha fazla anlatacağım (İşletim sistemi adı, bilgisayar adı, sürüm bilgileri, Çıkış adı, Makine tipi) script üzerinde çalışmakta olduğunu.