#!/usr/local/bin/perl -w use strict; print "Content-Type: text/html\n\n";#this sends html text, needsand here is the link to see how this code works.
#print "Content-Type: text/plain\n\n";#this sends plain text, need \n # use the second form, and reload the URL to see what happens print ("<h1>Here I am<//h1>\n"); print ("<HTML>"); print "<body>"; print "This is the first line."; print "This is the second line."; print "This doesn't work in html mode,\n, SEE!"; print "This is the third line."; print "<h1>This is a heading</h1>"; print "This doesn't work in plain mode,<br>,SEE!<br>"; print "This is the fourth line."; print "<font color=red size=+2> Here's some big red text<br></font>"; print "<h1>This is another heading</h1>"; print "</html>";
chmod a+x hello_world.plif, indeed, the name of the program is ``hello_world.pl''. If you issues a statement:
ls -al hello_world.plyou will see that hello_world is executable, i.e., that there are 3 x's showing.
-rwxr-xr-xThis makes the program executable by the owner, his group, and the world. Now, when you address this program via
http://www.your.server.address.whatever/~your_account/cgi-bin/hello_world.plthis program will ``execute'' on the server, and print in your local browser.
#!/usr/local/bin/perl
#from Terrence Jordan
# July, 1997, a super programmer.
# he has asked me to cite him in the following manner:
# Terence Jordan mailto:tatewake@mindless.com
# Inspired Software, http://inspired.netstreet.net/
#
#
#
#
#
#This subroutine and such takes all ENVironmental variables
# and "spits 'em back at you".
sub cgiparse{
if ($ENV{'REQUEST_METHOD'} eq "POST"){
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else {
$buffer = $ENV{'QUERY_STRING'};
}
local(@query_strings) = split("&",$buffer);
foreach $q(@query_strings){
$q =~ s/\+/ /g;
($attr,$val) = split("=", $q);
$val =~ s/%/\n/g;
local($tmpval);
foreach (split("\n",$val)){
if(m:%(\w\w):){
local($binval) = hex($1);
if(($binval>0)&&($binval<256)){
local($htmlval) = pack("C",$binval);
s/%$1/$htmlval/;
}
}
$tmpval .= $_;
}
$parseit{$attr} = $tmpval;
}
%parseit;
}
print "Content_Type: text/plain\n\n";
print "\n";
&cgiparse();
#THIS IS THE KEY STATEMENT COMING UP
print map {"\n"}keys %ENV;
print "\n\n\n";
and here is the
link to see how this code works.
#!/usr/local/bin/perl -w use CGI; $query = new CGI; print $query->header; print "<hr>"; print "The script's name = ",$query->script_name(),"<br>"; print "The script's referer = ",$query->referer(),"<br>"; print "The script's remote_host = ",$query->remote_host(),"<br>"; print "The script's request_method = ",$query->request_method(),"<br>"; print "The script's server_name = ",$query->server_name(),"<br>"; print "The script's server_port = ",$query->server_port(),"<br>"; print "The script's user_agent = ",$query->user_agent(),"<br>"; print "<hr>"; print $query->end_html;
Last revision/editing, September 30, 1997