From PHP, check if Apache variable is defined (same as IfDefine in .htaccess)
How can I check with PHP if an Apache variable is defined? This .htaccess
is checked using IfDefine.
When starting Apache, I define a variable: on Windows with
httpd.exe -D "MYVARIABLE" -w -n "Apache2.2" -k start
and in Ubuntu adding to /etc/apache2/envvars
:
export APACHE_ARGUMENTS='-D MYVARIABLE'
Now I can use it in .htaccess
like
<IfDefine MYVARIABLE>
do stuff
</IfDefine>
and it works.
How can I test this in PHP? I tried
if (getenv ('MYVARIABLE')) do stuff;
if (apache_getenv ('MYVARIABLE')) do stuff;
but it always returns FALSE
.
phpinfo ();
prints a lot of things, but there is no line in its output MYVARIABLE
.
source to share
Thanks to mario's comment, I think the answer is:
-
On Windows there is probably no way for a variable to be set as a command line argument like
httpd.exe -D "MYVARIABLE" -w -n "Apache2.2" -k start
-
On Linux / Ubuntu, if installed
/etc/apache2/envvars
asexport APACHE_ARGUMENTS='-D MYVARIABLE'
then from PHP
$x = getenv ('APACHE_ARGUMENTS')
gives
-D MYVARIABLE
from which you can usestrstr ($x, 'MYVARIABLE')
or so to find the variable.
source to share