1

Because of the infamous IIS bugs concerning the "Location" redirect header, we have to use the "Refresh" header instead.

So, I would like to know the best method to programmatically detect if PHP script is running under IIS.

Currently used method is DIRECTORY_SEPARATOR !== '/', but obviously Apache and other servers under Windows are uncorrectly recognized as IIS.

I thought about:

strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false

... but this element corresponds to the "Server" header of the HTTP response, and it may have been removed by various means.

Any ideas of robuster methods?

1 Answer 1

1

According to http://www.helicron.net/php/, IIS will leave $_SERVER['DOCUMENT_ROOT'] empty but apache will not.

Sign up to request clarification or add additional context in comments.

2 Comments

Yep, I had found this article too, but is this method safe enough? How do other servers than Apache and IIS behave? Do latest (and future) IIS versions still miss this element? Also, the article isn't dated but I guess it has been written for quite some time.
I have no idea about that, but I would just go for simple variable in web-app configuration to define currently used web-server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.