hi im a beginninger at perl/cgi and this cookie is hard to understand lol. I'm trying to modify the script so that it displays an appropriate Web page if the name passed to the script is blank. but i get this in the browser:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
Please return to the form complete name.
here is my cgi code:
#!C:/Perl/bin/perl.exe
#c11ex1b.cgi - displays a Web page containing the user's
#name and the book information
use CGI qw(:standard -debug);
#prevent Perl from creating undeclared variables
use strict;
#declare variables
my ($name, $C_name, $data_ok, $msg);
#assign input to variable
$name = param('Name');
$C_name = param('C_Name');
($name, $C_name) = format_input();
($data_ok, $msg) = validate_input();
if ($data_ok eq "N") {
create_error_page();
}
else {
create_cookie();
}
exit;
#*****user-defined functions*****
sub format_input {
my ($n, $e);
($n) = ($name);
#remove leading and trailing spaces from name
$n =~ s/^ +//;
$n =~ s/ +$//;
return $n;
} #end format_input
sub validate_input {
my ($valid, $errormsg);
$valid = "Y";
if ($name eq "") {
$valid = "N";
$errormsg = "complete name";
}
return $valid, $errormsg;
} #end validate_input
sub create_error_page {
print "<HTML>\n";
print "<HEAD><TITLE>Jubilee Book Club</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H2>Please return to the form $msg.</H2>\n";
print "</BODY></HTML>\n";
} #end create_error_page
sub create_cookie {
#create cookie
$C_name = cookie(-name => "Name",
-value => "$name",
-path => "/cgi-bin/chap11",
-expires => "+6M");
#send cookie to browser
print header(-cookie => $C_name);
#create Web page
print "<HTML>\n";
print "<HEAD><TITLE>Jubilee Book Club</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H1 ALIGN=center>Hello, $name!<BR>\n";
print "The book of the month is</H1><HR>\n";
print "<H2 ALIGN=center><FONT COLOR=red>\n";
print "<I>The Case of the Missing Dagger</I>\n";
print "<BR>by H.T. Sims\n";
print "</FONT></H2>\n";
print "</BODY></HTML>\n";
}