views:

204

answers:

3

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!

+7  A: 

You could use SetEnvIf and <IfDefine>:

# default value
php_flag error_reporting 0

# exceptional value
SetEnvIf Remote_Addr ^12\.34\.56\.78$ debug_mode
<IfDefine debug_mode>
    php_flag error_reporting 1
</IfDefine>
Gumbo
A: 

SetEnv doesn't seem to work for me. I tried this in my .htaccess:

SetEnvIf Remote_Addr ^192\.168\.0$ ip_ok
<IfDefine !ip_ok>
  AuthName "Guest Login"
  AuthType Basic
  AuthUserFile /opt/lampp/lib/ok_users/guests.users
  require valid-user
</IfDefine>

and I had to provide username/password credentials even though my ip is 192.168.0.10 and the server (centos5 / xampp for linux 1.6.8a) is 192.168.0.1

So I tried this:

SetEnv ip_ok
<IfDefine !ip_ok>
  AuthName "Guest Login"
  AuthType Basic
  AuthUserFile /opt/lampp/lib/ok_users/guests.users
  require valid-user
</IfDefine>

but setenv does not set ip_ok, and I still get challenged.

Then I tried this:

SetEnv ip_ok
<IfDefine ip_ok>
  AuthName "Guest Login"
  AuthType Basic
  AuthUserFile /opt/lampp/lib/ok_users/guests.users
  require valid-user
</IfDefine>

and I don't get challenged. Therefore IfDefine is working.

Any ideas why I can't get SetEnv and SetEnvIf to work?? I've googled and read but can't crack it.

kerry