A quick CGI script to dump all of the environment variables, form data, and cookie information. Very handy for troubleshooting. #!/usr/bin/perl ################################################################################ # $Id: env.cgi 39 2009-08-12 13:18:36Z v89326 $ # $URL: file:///S:/svn/utilities/trunk/env.cgi $ ################################################################################ # # Title: env.cgi # Author: Kurt Kincaid # VERSION: 0.0.1 # ################################################################################ use CGI ':standard'; use CGI::Carp 'fatalsToBrowser'; use strict; our ( $the_cookie ); $the_cookie = cookie( -name => 'Test1', -value => "This is the first test", -expires => "+1h" ); print header( -cookie => $the_cookie ); print start_html( "Environment Dump" ); dumpEnv(); sub dumpEnv { my $query = new CGI; print qq~<table align="center" border="1" width="100%" style="border: 2px solid black;"> <tr> <th colspan="2">Environment Variables</th> </tr> <tr> <th>Key</th> <th>Value</th> </tr> ~; foreach my $key ( sort { lc( $a ) cmp lc( $b ) } keys %ENV ) { print qq~<tr> <td>$key</td> <td>$ENV{ $key }</td> </tr> ~; } print "</table><br><hr><br>\n"; if ( $query ) { my @param = $query->param; print qq~<table align="center" border="1" width="100%" style="border: 2px solid black;"> <tr> <th colspan="2">CGI values</th> </tr> <tr> <th>Key</th> <th>Value</th> </tr> ~; foreach my $param ( sort { lc( $a ) cmp lc( $b ) } @param ) { my $val = $query->param( $param ); print qq~<tr> <td>$param</td> <td>$val</td> </tr> ~; } print( "</table><br><hr><br>\n" ); } print qq~<table align="center" border="1" width="100%" style="border: 2px solid black;"> <tr> <th colspan="2">Cookie values</th> </tr> <tr> <th>Key</th> <th>Value</th> </tr> ~; my @cookies = cookie(); if ( scalar @cookies ) { foreach my $param ( sort { lc( $a ) cmp lc( $b ) } @cookies ) { my $val = $query->cookie( $param ); print qq~<tr> <td>$param</td> <td>$val</td> </tr> ~; } print "</table>\n"; } else { print qq~<tr><td colspan="2" style="color: red">'Test1' not set. Either cookies are disabled, or this is the first run. Try refreshing the page.</td></tr> </table> ~; } return 0; } ################################################################################ # EOF |
Perl Code >