How to use PHP files with custom error page in Web.config

1

I have a file named error.php , it takes the value GET or an already defined variable and displays the errors in multiple languages and of all types.

I use IIS and already tried in Web.config to use PHP pages, but I did not succeed, I only get HTML pages that is not my purpose.

How can I use the error.php file as an error page in Web.config?

Current Web.config:

    <?xml version="1.0" encoding="UTF-8">
    <configuration>
       <system.webServer>
            <httpErrors errorMode="Custom">
                <remove statusCode="401" />
                <error statusCode="401" path="sys\error1.html responseMode="File" />
                .....
            </httpErrors>
        </system.webServer>
    </configuration>

And I tried to use it in the following way, but it did not work:

 <error statusCode="401" path="sys\error.php?number=401" responseMode="File" />
    
asked by anonymous 26.02.2016 / 20:18

1 answer

2

I think that responseMode="File" sends the response as if the file were a static file, if you want to "execute" it, you should not use \ inverted in this case and the path should start from "root" / with bar in front) like this:

<error statusCode="401" path="/sys/error.php?number=401" responseMode="ExecuteURL" />
Tested on IIS8 Express , I believe it does not change in the IIS default and version 7.

  

Note:

     

I believe that status codes can not be customized: 400, 403.9, 411, 414, 500, 500.11, 500.14, 500.15, 501, 503, and 505.

     

link

If it does not work just try:

<error statusCode="401" path="/sys/error.php" responseMode="ExecuteURL" />

And instead of using _GET use the function http_response_code() ( requires php5.4 +) do this in your error.php :

<?php
echo http_response_code();

    
27.02.2016 / 02:38