How can I turn on PHP errors display on just a subfolder

前端 未结 4 1287
你的背包
你的背包 2020-12-31 04:59

I don\'t want PHP errors to display /html, but I want them to display in /html/beta/usercomponent. Everything is set up so that errors do not displ

4条回答
  •  臣服心动
    2020-12-31 05:34

    you could do this by using an Environment variable. this way you can have more choices than just turning Error reporting on/off for a special directory. in your code where ever you wanted to change any behaviour for a specific set of directoris, or running modes, check if a environment variable is set or not. like this:

    if ($_ENV['MY_PHP_APP_MODE'] == 'devel') {
      // show errors and debugging info
    } elseif ($_ENV['MY_PHP_APP_MODE'] == 'production') {
     // show some cool message to the user so he won't freak out
     // log the errors and send email to the admin
    }
    

    and when you are running your application in your development environment, you can set an env variable in your .htaccess file like this:

     setenv MY_PHP_APP_MODE devel
    

    or when you are in production evn:

     setenv MY_PHP_APP_MODE production
    

    the same technique applies to your situation. in directories where you want to do something special (turn on error reporting) set some env variable and in your code, check for that.

提交回复
热议问题