Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional php_flag statements in .htaccess

Is there a way to conditionally execute php_flag statements in .htaccess? Here are two things I'm trying to do:

Turn error reporting on if the client's IP address matches the IP address I use:

if %{REMOTE_ADDR} == '12.34.56.78' then
   php_flag error_reporting 1
else
   php_flag error_reporting 0

Turn off register_globals if the IP address matches mine, so that I can debug any issues caused by the code expecting this turned on.

if %{REMOTE_ADDR} == '12.34.56.78' then
   php_flag register_globals on
else
   php_flag register_globals on

Thanks for reading!

like image 512
i-g Avatar asked Feb 13 '10 17:02

i-g


1 Answers

if %{REMOTE_ADDR} == '12.34.56.78' then
   php_flag error_reporting 1
else
   php_flag error_reporting 0

This is only really possible with the advent of Apache Expressions in Apache 2.4+, where you can do just this sort of thing...

<If "%{REMOTE_ADDR} == '12.34.56.78'">
    php_flag error_reporting 1
</If>
<Else>
    php_flag error_reporting 0
</Else>

If on Apache 2.2 this is not really possible, especially with something that is dependent on the request, like the REMOTE_ADDR. On Apache 2.2 you have <IfDefine>, but this only tests the existence of parameters that have been defined on the Appache command line with the -D option. So, this is really a per-server configuration switch. (On Apache 2.4 you can use the Define directive in the server config to define parameters somewhat conditionally, however, this still can't be defined based on elements of the request AFAIK. Besides, you have the use of Apache Expressions on Apache 2.4 anyway.)

like image 129
MrWhite Avatar answered Oct 24 '22 09:10

MrWhite