Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So on an Apache bundled with PHP as a module, I want to prepend a file if referer is x. This is what I have so far:

<IfModule mod_setenvif.c>
    SetEnvIf Referer http://backoffice\.mywebsite\.wan27/ BackOfficeListens
</IfModule>

<IfDefine BackOfficeListens>
    <IfModule mod_php5.c>
        php_value auto_prepend_file /path/to/php/file
    </IfModule>
</IfDefine>

I should also say to the BackOffice Server is on my local, so backoffice.mywebsite.wan27 is a local host, but apparently the PHP on the target server recognizes it.

share|improve this question

1 Answer 1

You can't use IfDefine to test the values of an environment variables. Take a look at the core Apache documentation, specifically:

The parameter-name argument is a define as given on the httpd command line via -Dparameter- , at the time the server was started.

I don't know the best way of handling this. One option would be to always prepend the file:

SetEnvIf Referer http://backoffice\.mywebsite\.wan27/ BackOfficeListens
php_value auto_prepend_file /path/to/php/file

And then inside the PHP file, check for your environment variable and perform your intended logic only if the variable is set:

<?php

if (isset($_ENV['BackOfficeListens'])) {
    echo("BackOfficeListens is set.");
}

?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.