I typically look for $ENV{'SERVER_NAME'} or other items that are set automatically by the webserver, with the assumption that most people's shell won't have it set. Another good one to check might be $ENV{'GATEWAY_INTERFACE'}.
| [reply] |
That is not always going to work. If I remember correctly if you run under mod_perl, you start with an extremely limited environment, such as:
MOD_PERL = mod_perl/2.0.1
MOD_PERL_API_VERSION = 2
PATH = X:\webserver\perl\bin\;C:\WIN ...
and that's it.Checking the environment is probably not very portable either.
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] [d/l] |
The question was specifically about CGI. As part of the CGI specification, you'll see that some environmental variables are specifically set for every request. (including the two I mentioned originally)
It's always possible that some of the other more-than-just-CGI implementations (FastCGI, mod_perl, etc), behave differently, as well as software that doesn't correctly implement the CGI specifications.
However, for my install of mod_perl (using Apache::Registry, Apache 1.3, Mac OS X), in using the following simple script:
#!/usr/bin/perl --
use Data::Dumper;
print "Content-Type: text/plain\n\n",
Dumper \%ENV;
I get after censoring out the host name:
You'll notice that 'GATEWAY_INTERFACE' is still defined, and indicates that it's not a standard CGI.
Using Apache::PerlRun is the almost identical:
| [reply] [d/l] [select] |