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:
$VAR1 = { 'SCRIPT_NAME' => '/cgi/test-cgi', 'SERVER_NAME' => '[censored]', 'SERVER_ADMIN' => '[no address given]', 'PERL_SEND_HEADER' => 'On', 'REQUEST_METHOD' => 'GET', 'SCRIPT_URI' => 'http://[censored]/cgi/test-cgi', 'SCRIPT_FILENAME' => '/Library/Webserver/Mod_Perl-Executable +s/test-cgi', 'SERVER_SOFTWARE' => 'Apache/1.3.33 (Darwin) mod_perl/1.29', 'QUERY_STRING' => '', 'REMOTE_PORT' => '53739', 'SERVER_SIGNATURE' => '<ADDRESS>Apache/1.3.33 Server at [cen +sored] Port 80</ADDRESS> ', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'SERVER_PROTOCOL' => 'HTTP/1.0', 'PATH' => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/Syste +m/Library/CoreServices', 'REQUEST_URI' => '/cgi/test-cgi', 'GATEWAY_INTERFACE' => 'CGI-Perl/1.1', 'SCRIPT_URL' => '/cgi/test-cgi', 'SERVER_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/Library/WebServer/Documents', 'MOD_PERL' => 'mod_perl/1.29' };
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:
$VAR1 = { 'SCRIPT_NAME' => '/perl/test-cgi', 'SERVER_NAME' => '[censored]', 'SERVER_ADMIN' => '[no address given]', 'PERL_SEND_HEADER' => 'On', 'REQUEST_METHOD' => 'GET', 'SCRIPT_URI' => 'http://[censored]/perl/test-cgi', 'SCRIPT_FILENAME' => '/Library/Webserver/Mod_Perl-Executable +s/test-cgi', 'SERVER_SOFTWARE' => 'Apache/1.3.33 (Darwin) mod_perl/1.29', 'QUERY_STRING' => '', 'REMOTE_PORT' => '53741', 'SERVER_SIGNATURE' => '<ADDRESS>Apache/1.3.33 Server at [cen +sored] Port 80</ADDRESS> ', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '127.0.0.1', 'SERVER_PROTOCOL' => 'HTTP/1.0', 'PATH' => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/Syste +m/Library/CoreServices', 'REQUEST_URI' => '/perl/test-cgi', 'GATEWAY_INTERFACE' => 'CGI-Perl/1.1', 'SCRIPT_URL' => '/perl/test-cgi', 'SERVER_ADDR' => '127.0.0.1', 'DOCUMENT_ROOT' => '/Library/WebServer/Documents', 'MOD_PERL' => 'mod_perl/1.29' };
In reply to Re^4: Telling if your script is running from web page or CLI
by jhourcle
in thread Telling if your script is running from web page or CLI
by dizzyg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |