Use environment variables with If statements

I was wondering if there is a way to use environment variables (or similar) with an if statement to turn certain things on or off like display_errors, modpagespeed.

So for example:

SetEnv DISPLAY_ERRORS on

<If "DISPLAY_ERRORS == on">
    php_flag display_errors on
</If>
<If "DISPLAY_ERRORS == off">
    php_flag display_errors off
</If>

      

I have spent quite a bit of time looking for such a thing, but I have not been able to reveal anything that does this. Is it possible?

I'm looking for an easy way to edit htaccess using PHP, but instead of writing blocks in htaccess, it would be easier to just change the "on" and "off" values ​​and also make it easier to display that as radio buttons in my application.

+3


source to share


1 answer


We might be tempted to write the following:

#SetEnvIf Request_URI "^" DISPLAY_ERRORS=off
SetEnv DISPLAY_ERRORS off

<If "-T env('DISPLAY_ERRORS')">
    php_flag display_errors off
</If>
<Else>
    php_flag display_errors on
</Else>

      

But it seems to be <If>

evaluated before anyone SetEnv(If)

.

Note that the value of a variable may depend on the phase of request processing in which it is evaluated. For example, the expression used in the directive <If >

is evaluated before authentication is complete



Another working approach I mean would be:

<IfDefine DISPLAY_ERRORS>
    php_flag display_errors on
</IfDefine>
<IfDefine !DISPLAY_ERRORS>
    php_flag display_errors off
</IfDefine>

      

And starting from Apache with an argument -DDISPLAY_ERRORS

to display errors or for Apache> = 2.4 add Define DISPLAY_ERRORS

to the virtual host config.

+4


source







All Articles