How do I set cookies using Perl CGI?

2019-09-21 06:53发布

问题:

I have tried without success setting cookies using Perl CGI.

My code looks like this:

$qry = new CGI

$cookie = $qry->cookie(-name=>'SERVER_COOKIE',
                       -value=>'USER_NAME',
                       -path=>'/'),
$qry->header(-cookie=>$cookie)

The page does not throw any error, but no cookie gets set!

I am using Firefox 3.5.5 with the add-on to view cookies.

What am i doing wrong?

Gath

回答1:

If your missing semicolons are just an artifact of pasting your question, the key point here is that you need to print the call to header for it to get sent to the browser.

print $qry->header(-cookie=>$cookie);


标签: perl cookies cgi