the ones I set with [E] aren't showing up
... Apache (or mod_perl) don't pass on environment variables from the shell by default; you'll have to specify these using either the standard PassEnv or mod_perl's PerlPassEnv directives.
Second, the Apache HTTP Server provides a mechanism for storing information in named variables that are also called environment variables. This information can be used to control various operations such as logging or access control. The variables are also used as a mechanism to communicate with external programs such as CGI scripts.
The most basic way to set an environment variable in Apache is using the unconditional SetEnv directive.
Environment variables can then be used in a variety of contexts, including CGI programs, ...
i always thought the [E] flag was equivalent to SetEnv(If)The complication is that, by the usual reverse-alphabetical-order guideline, mod_rewrite (RewriteRule with [E] flag, OR RewriteCond looking at %{ENV:blahblah}) executes after mod_setenvif (SetEnvIf directive) but before mod_env [httpd.apache.org] (simple SetEnv directive). But of course this is only relevant if you're using the environmental variable in a RewriteRule. By the time you reach the page--whether it's php, perl or something else--everything should be set regardless.
RewriteRule ^/(?:(?:includes|images|cgi-bin|cache)/)|404\.php - [PT] foreach (sort keys %ENV) {
$$_ = $ENV{$_};
}
a way to select JUST the environment variables that I set?
foreach (sort keys %ENV)Could the "foreach" be replaced with something that takes an argument, using the specific name of the variable you’re interested in?
If I'm reading correctly, though, it would still convert all of them, right?
The Env::import() function ties environment variables with suitable names to global Perl variables with the same names. By default it ties all existing environment variables (keys %ENV) to scalars. If the import function receives arguments, it takes them to be a list of variables to tie; it's okay if they don't yet exist.
RewriteRule ^ - [E=foo:bar]
RewriteRule ^ - [E=lorem:ipsum] use Env::import('foo'); Let's not talk about something clunky like putting in a further loop to the effect of "if {thing I'm currently looking at} == {some specific value} then-and-only-then {do stuff}".
foreach (keys %ENV) {
if ($_ == lc($_)) {
$$_ = $ENV{$_};
}
} This is a site that's still in development, of course, and I might add variables to the .conf that I would want to carry over to php, cgi, pl, and lib scripts.
I was absolutely NOT about to suggest writing my variables in lower case, then in the loopHaha, see, that’s pretty exactly what I ended up doing in my logheaders routine when I expanded it to record any environmental variables that I’ve set. Turns out there’s a slew of variables set by the server that I’m not interested in, but fortunately they are in ALL_CAPS while my own variable names are lower-case. So I really do have a loop that says "if the name of the environmental variable starts with a lower-case letter, AND it has a non-zero value, then do this extra thing”.
but you would have to change the script(s) to use the new variable, correct?
it seems like adding another argument to the list of tied variables is a small effort compared to implementing new code using the new variable elsewhere in the script.
So I really do have a loop that says "if the name of the environmental variable starts with a lower-case letter, AND it has a non-zero value, then do this extra thing”.
I didn't think about checking for a non-zero value. If it's '' or 0, maybe I should set the scalar to false?This is probably a site-specific question. I do it because sometimes I set a variable and later un-set it, and I want to make double-sure the unset ones are ignored. (Apache docs say it is “removed”, but sometimes I am over-anxious.) On the other hand, if your environmental variables might actually have a value of zero or empty string, then obviously you should not impose this limitation.
Timing is also important. Foo needs to be set to bar before lorem can be set to ipsum.So that's a situation where ordering of modules--assuming you're setting them in Apache before arriving at your script--can make a difference. Stuff that if done in mod_setenvif will be available to mod_rewrite but not vice versa, and stuff done in mod_env will not be available to either of the others.
He could also be subject to suexec security issues. In such a case, he will need to prepend his variables with HTTP_.