Page 1 of 1

Cookies with PERL in CGI

Posted: Thu May 19, 2011 7:35 pm
by cah
I was able to write the cookies to browsers and see the values in them.
However, I am unable to modify the values in the cookies.

It is impossible to have the following call again:

print $cgi->header(-cookie=>$c, -charset=>'Big5');

$c->bake will simply print the header on HTML page and will not update cookies in browsers.

Re: Cookies with PERL in CGI

Posted: Wed May 25, 2011 2:44 pm
by cah
The key is $cgi->header().
It can only be called once in any given instance.

Therefore, how to arrange the header to be printed is very important.
The cookie header MUST be printed before regular HTML header is printed.

If any error messages need to be shown on web pages, create if statement to print error messages only.
Print cookie header when there's no errors and no need to print HTML first.

Once the header (including cookie header) is printed, HTML can then follow.

Re: Cookies with PERL in CGI

Posted: Wed Oct 26, 2011 2:33 pm
by cah
Refer working code (sign_in.cgi) in my wedding site (/export/home/www/mirror/cah/wedding)