PHP – Check If a Web Server is running on Windows or Linux

The following code shows you how to check if a web server is running on Windows or Linux by looking at PHP_OS const.

example.php
if (PHP_OS === 'WINNT') {
    echo 'This is a server using Windows';
} else if (PHP_OS === 'Linux') {
    echo 'This is a server using Linux';
} else {
    echo 'using another os';
}

0 0 vote
Article Rating
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
henry
henry
2 years ago

it works, thnx
keep it up

Barak
Barak
1 year ago

it works fine for me

2
0
Would love your thoughts, please comment.x
()
x