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

Asked

Viewed 142 times

1

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

I use IIS and have tried on Web.config to use PHP pages, but I did not succeed, I can only with HTML pages that is not my purpose.

How can I use the.php error 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\error\401.html responseMode="File" />
                .....
            </httpErrors>
        </system.webServer>
    </configuration>

And I tried to use it this way, but it didn’t work:

 <error statusCode="401" path="sys\error.php?number=401" responseMode="File" />
  • People excuse how the question is, I did the phone but I could not get as wanted...and now to edit it bugged all the text... I AM FIXING!

  • Almost certain the formation, needs the 4 spaces and also skip a line to separate. For example after the web.config atual: enter :)

  • Didn’t work as? Appeared the default page is this? or appeared another error?

1 answer

2


I believe that responseMode="File" send the reply as if the file were a static file, if you want to "run it", you should not use \ reversed 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 in IIS8 Express, I believe it will not change in IIS standard and not in version 7.

Note:

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

https://technet.microsoft.com/en-us/library/cc753103%28v=Ws.10%29.aspx? f=255&Mspperror=-2147217396

If it doesn’t 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 on your php error.:

<?php
echo http_response_code();

  • The page was blank, using the 2 methods of Executeurl

  • @Vinicius which php version? Tried without the ? number= ?

  • The version of my PHP is 5.6.18 the last. I would like to use 7.0.3 but there is no support for PDO sqlsrv. I tried yes without it, but it was also empty

  • 1

    Worked by putting / at the beginning, thank you very much! If you can please edit the reply saying that it is necessary by / at first thank you :)

  • About the http_response_code(); he always returns 202

  • @Vinicius which version of IIS?

  • I believe it is version 6.0 of IIS, because apparently 7 has no support for Windows 10

  • @Vinicius thank you, tomorrow I research about this problem and update, GET works normal?

  • 1

    No bro your answer worked I just had to /sys/error.php?number=404 what has changed is only the / at the beginning. GET works normal too

  • 1

    @Vinicius took the test with http_response_code always returns me 200 (IIS8 express), removed that part of the answer.

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.