Cookie retrieval error in perl

Asked 1 years ago, Updated 1 years ago, 104 views

a. Set cookies in cgi and
Trying to read cookies from b.cgi in the same hierarchy
Then an error occurs.

b.
by specifying the $main->param(READID=>$readid); in cgi There seems to be an error, but I don't know the cause.
What kind of instructions are appropriate?
I would appreciate it if you could let me know.
Thank you for your cooperation.

■ a.cgi

use CGI;
use HTML::Template;

my$q = CGI->new;
my$readid=$q->cookie("id");
$main->param(READID=>$readid);

print "Content-Type:text/html\n";
print "Set-Cookie:id=$id;expires=Tue, 1-Jan-2030 00:00 GMT; path=/;\n";

my$main=HTML::Template->new(filename=>'./tpl/main.tpl');

The contents of the cookies are displayed in the above template.

■ b.cgi

use CGI;
use HTML::Template;

my$q = CGI->new;
my$readid=$q->cookie("id");
$main->param(READID=>$readid);

■ Error contents
[error] Can't call method "param" on undefined value
[error] Premium end of script headers: b.cgi

Thank you for your cooperation.

perl cookie

2022-09-30 20:55

1 Answers

The method call failed because the $main value is undef.b. Not only cgi, but a.cgi should get the same error.

To prevent such errors, it is recommended to start with use strict; (also use warnings;), which results in an error if a variable is not declared by use strict


2022-09-30 20:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.