Hi all,
Can anyone guess why this is happening? I am new to Perl, so please help me to fix this error:
- I have a static html file which calls the cgi-perl script.
HTML Code:
<html>
<head>
<title> Hey Dude! </title>
</head>
<body>
<form method="POST" action="/cgis/dude.pl">
<p><input type="text" name="name" size="49"></p><br>
<p><input type="submit" name="submit" value="GO!"></p><br>
</form>
</body>
</html>
and my CGI-PERL code is:
#!/usr/bin/perl -w
# Read the standard input (sent by the form):
read(STDIN, $form, $ENV{'CONTENT_LENGTH'});
# Get the name and value for each form input:
@pairs = split(/&/, $form);
# Then for each name/value pair....
foreach $pair (@pairs) {
# Separate the name and value:
($name, $value) = split(/=/, $pair);
# Convert + signs to spaces:
$value =~ tr/+/ /;
# Convert hex pairs (%HH) to ASCII characters:
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Store values in a hash called %FORM:
$form{$name} = $value;
}
#This will generate XHTML-compliant page headers
sub start_html()
{
print qq~
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Cookies </title>
</head>
<body>
~;
}
if ($form{'submit'} eq "submit")
{
#Start hearders
print "Set-Cookie: name=$form{'name'}\n";
print "Content-Type: text/html\n\n";
#end of headers
&start_html();
print "Nice to meet you $form{'name'}", ". I hope to see you again soon";
}
else
{
$old_cookie = $ENV{"HTTP_COOKIE"};
#if cookie was found
if ($old_cookie)
{
($cookie_name, $name) = split(/=/, $old_cookie);
#start headers
print "Content-Type: text/html\n\n";
#end of headers
&start_html();
print "Hey! I know you dude! You are $name";
print "</body></html>\n";
}
#cookie not fond
else
{
# redirect user to the form with a redirect header
print "Location:http://mydomain.com/dude.html\n\n";
}
}
Error in log_error:
[client 10.10.192.168] Name "main::cookie_name" used only once: possible typo at /dir/cgi-bin/dude.pl line 49., referer: http://mydomain.com/dude.html