How to test from PHP whether an Apache variable is defined? In .htaccess
this is tested with IfDefine.
When starting Apache, I define a variable: in 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
as
<IfDefine MYVARIABLE>
do stuff
</IfDefine>
and it works.
How can I test for it from 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 string MYVARIABLE
in its output.
Thanks to mario's comment, I think the answer is:
On Windows, probably no way when the variable is set as a command line argument, such as
httpd.exe -D "MYVARIABLE" -w -n "Apache2.2" -k start
On Linux/Ubuntu, if it is set in /etc/apache2/envvars
as
export APACHE_ARGUMENTS='-D MYVARIABLE'
then from PHP
$x = getenv ('APACHE_ARGUMENTS')
gives -D MYVARIABLE
, from which you can use strstr ($x, 'MYVARIABLE')
or so to find the variable.