Hammy has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I am have some very simple code that is completely baffling me. I have an HTML file that sets cookies. I have another html file that displays the cookies perfectly. I have also written a simple Perl script that does not show the cookies consistently. I have listed each piece of code below:
Set the cookie - works as expected:
Show the cookie with HTML - works as expected:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HEAD> <TITLE>Test</TITLE> <script type='text/Javascript'> document.cookie="ff=1;"; document.cookie="gg=;"; </script> </HEAD> <BODY> Cookie Set </BODY> </HTML>
Show the cookie with Perl - only works if cookie is empty<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> Test </TITLE> </HEAD> <BODY> <script type='text/Javascript'> alert(document.cookie); </script> </BODY> </HTML>
I have tried this on a few servers.#!/usr/bin/perl use CGI::Cookie; %cookies = fetch CGI::Cookie(); $ctab .= "<table border=1>"; $ctab .= "<tr><td>Name</td><td>Value</td></tr>\n"; foreach $c (keys %cookies) { $v = $cookies{$c} -> value(); $ctab .= "<tr><td>$c</td><td>$v</td></tr>\n"; } $ctab .= "</table><BR><BR>"; print "Content-type: text/html\n\n"; print $ctab;
One: Free BSD / Apache 1.3.41 / Perl 5.6.1 shows both cookies with Perl and both with html.
Two: Red Hat ES 4 / Apache 2.0.52 / Perl 5.8.5 shows no cookies with Perl script and both with html.
Three: Red Hat 5.3 / Apache 2.2.3 / Perl 5.8.8 shows only empty cookies (gg) with Perl and both with html.
I have no idea why javascript shows the cookies are there and Perl does not recognize them. Any help would be greatly appreciated. Thank You.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Problems reading ALL cookies
by ahmad (Hermit) on Apr 22, 2010 at 18:41 UTC | |
Re: Problems reading ALL cookies
by ig (Vicar) on Apr 22, 2010 at 19:23 UTC | |
by Hammy (Scribe) on Apr 22, 2010 at 19:52 UTC | |
by ig (Vicar) on Apr 23, 2010 at 06:30 UTC | |
by Hammy (Scribe) on Apr 23, 2010 at 15:38 UTC | |
Re: Problems reading ALL cookies
by AR (Friar) on Apr 22, 2010 at 19:27 UTC |
Back to
Seekers of Perl Wisdom