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:

<!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 HTML - works as expected:
<!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>
Show the cookie with Perl - only works if cookie is empty
#!/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;
I have tried this on a few servers.

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.


In reply to Problems reading ALL cookies by Hammy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.