Place inside an existing CGI that uses CGI.pm.

Pretty self-explanatory, but any argument passed on the URI field of your browser will be turned into a variable used by CGI.pm. Yes, this has several concerns, the most of which is the ability to override the default vars, so remember to always check your variables first when you get them. Using http://www.foo.com/bar=blort&baz=quux will result in $bar=blort and $baz=quux being created for you.

The second piece of that simply prints out the entire environment as passed to your webserver, inside the comment block of your HTML. WARNING: Do not leave this uncommented in production code!!! (unless you want people to see your server paths and other variables, thus making it easier to exploit). Use the second snippet for debugging purposes only!

#!/usr/bin/perl -w use Env; foreach $key ( param() ) { $$key = param($key) unless $$key; } print "<!--\n"; foreach $parameter ( sort keys %ENV ) { print "$parameter is: $ENV{$parameter}\n"; } print "-->\n";

In reply to Creating vars from URI and printing %ENV by hacker

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.