Yeah, it's pretty cool.

If you're on posix , fire up a terminal and type 'set' 'env' (thank you fullermd!), this shows you the system environment variables. All of these are accessible in your perl script as : $ENV{VARNAME}.

This is nifty, like with $ENV{HOME}- of what user your script is running as.

The catch is .. the environment variables available to your script running called from apache will access different environment variables as called from the command line,

So that..

#!/usr/bin/perl use CGI ':all'; print header; print "<pre>\n"; map { print "$_ $ENV{$_}\n" } sort keys %ENV; print "</pre>\n";

Gives you different results if called via cli or via apache (or other httpd).

For example, cgi side, you will see 'DOCUMENT_ROOT', which is not present under the cli side. Inversely, HOME is set on cli side, but not on cgi side. Likely for security reasons.

Different http servers will have different variables set. This depends on the configuration of the specific box in question.


In reply to Re: how to access apache environment variables by leocharre
in thread how to access apache environment variables by patpark

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.