tags:

views:

221

answers:

1

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

+6  A: 

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);
Adam Bellaire
I tried this but it just shows outputs the set_cookie command on the browser, but no cookie get set!
gath
@gath: If you are seeing the output in the browser, it's because you have already output HTTP headers somewhere prior to this. This line must be the very first thing output by your CGI script.
Adam Bellaire
True, it does set the cookie when print CGI->header(-cookie=>$cookie) is the first line on the script. Am now left wondering how ill set the cookie with a different value after filling up my from ... let me think
gath