All, I am having problem setting cookie manually. Hoever, I have no problem setting it via CGI qw(:standard). But for my educational purppose, I would like to know why this piece of code is not setting my cookie.

#!/usr/bin/perl # example_5-1.cgi use strict; print qq(Content-type: text/html\n"); print qq(Set-Cookies: username=Fred Flinstone; ); print qq(expires=Mon, 01-May-2003 00:00:00 GMT; ); print qq(path=/); print qq(\n\n); print qq(A cookie has been set in your browser...<P>); print qq(<A HREF="example_5-2.cgi">); print qq(Click to view the cookie</A>);

here's the code that checks if the cookie is set:

#!/usr/bin/perl #example_5-2.cgi use strict; my ($key,$value) = split(/=/,$ENV{HTTP_COOKIE}); print qq(Content-type: text/html\n\n); print qq(The cookie <B>$key</B> contained <B>$value</B>);

When I call the code via my browser: http://localhost/cgi-bin/play/example_5-1.cgi this sets the cookie and http://localhost/cgi-bin/play/example_5-2.cgi this displays it, but the cookie is not displaying. I even check Konqueror for the cookie, but there's nothing there from localhost. Does any one see anything wrong with this? Thanks.


In reply to cookie problem by perlknight

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.