[thelist] Quick and Dirty Environment Variables....

Anthony Baratta Anthony at Baratta.com
Fri Jan 25 15:17:00 CST 2002


<tip author="Anthony Baratta" subject="Scripts for Showing Environment
Variables">
I always carry a few scripts around to blast environment variables and form
values to the screen during development. While trying to debug a form
submission process gone awry I use these scripts as the action for the form
to prove/disprove the key value pairs of what is being submitted to the
"process script" (which might be itself).

These types of scripts are also useful in reminding you what the server has
available to your coding environment.

___ ASP ___
Note: We use the CapRock Consulting Dictionary Object so we can stuff
dictionary objects into Session Objects.

<%
OutLf "<h2>Form Info</h2>"
OutLf "<ul>"
for each fld in Request.Form
     OutLf "<b>" & fld & "</b>:&nbsp;&nbsp;" & Request.Form(fld) & "<br>"
next
OutLf "</ul><br><br>"

OutLf "<h2>Session Info</h2>"
OutLf "<ul>"
     for each strKey in Session.Contents
         OutLf "<h3>Session " & strKey & "</h3>"
         OutLf "<ul>"
         if isObject(Session(strKey)) then
             Set dictPrintOut = Server.CreateObject("caprock.dictionary")
             Set dictPrintOut = Session(strKey)
             for each fld in dictPrintOut
                 OutLf "<b>" & fld & "</b>:&nbsp;&nbsp;" &
dictPrintOut(fld) & "<br>"
             next
         else
             OutLf "<b>" & strKey & "</b>:&nbsp;&nbsp;" &
CStr(Session(strKey)) & "<br>"
         end if
         OutLf "</ul><br><br>"
     next
OutLf "</ul><br><br>"

OutLf "<h2>HTTP Env Info</h2>"
OutLf "<ul>"
for each fld in Request.ServerVariables
     OutLf "<b>" & fld & "</b>:&nbsp;&nbsp;" & Request.ServerVariables(fld)
& "<br>"
next
OutLf "</ul><br><br>"

SUB OutLf(varOut)
     Response.Write varOut & vbCRLF
END SUB
%>


___ Perl ___

#! /usr/bin/perl

use CGI;
$query = new CGI;
print $query->header;
print $query->start_html(-title=>"Env Variables");

print $query->h2('Form info') . "\n";
print "<ul>\n";
for $var (sort $query->param){
	print $query->b($var) . ": " . $query->param($var) . "<br \>\n";
}
print "</ul><br><br>\n";

print $query->h2('Environment info') . "\n";
print "<ul>\n";
for $var (sort keys %ENV){
	print $query->b($var) . ": " . $ENV{$var} . "<br \>\n";
}
print "</ul><br><br>\n";
print $query->end_html();

exit;


</tip>
---
Anthony Baratta
President
Keyboard Jockeys

"Conformity is the refuge of the unimaginative."




More information about the thelist mailing list