Cookies with PERL in CGI

Moderator: cah

Post Reply
cah
General of the Army / Fleet Admiral / General of the Air Force
General of the Army / Fleet Admiral / General of the Air Force
Posts: 1342
Joined: Sun Aug 17, 2008 5:05 am

Cookies with PERL in CGI

Post 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.
CAH, The Great
cah
General of the Army / Fleet Admiral / General of the Air Force
General of the Army / Fleet Admiral / General of the Air Force
Posts: 1342
Joined: Sun Aug 17, 2008 5:05 am

Re: Cookies with PERL in CGI

Post 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.
CAH, The Great
cah
General of the Army / Fleet Admiral / General of the Air Force
General of the Army / Fleet Admiral / General of the Air Force
Posts: 1342
Joined: Sun Aug 17, 2008 5:05 am

Re: Cookies with PERL in CGI

Post by cah »

Refer working code (sign_in.cgi) in my wedding site (/export/home/www/mirror/cah/wedding)
CAH, The Great
Post Reply