For setting a cookie I used
print $mycgi->header(-cookie=>$params->cookie(-name=>'sessionID', -value=>'some stuff', -expires=>'0', -path=>'/'));
and for reading it: <CODE> $mycgi->cookie(-name=>'sessionID'); <CODE>

CGI.pm's object interface really makes code cleaner. One assumes that the function oriented way you did it SHOULD work.

There are a bunch of other pitfalls with cookies though. One of the simplest ones to have is the "path problem". Netscape may not think it SHOULD return the cookie, because it may think its talking to a different web server.

In HTTP/1.1 the client sends a header that tells the web server what domain it is requesting a response from. The web server may be configured (IE apache "ServerName" directive) to return a response telling the browser the response came from a DIFFERENT domain, as in client asks for a page from www.rhombus.net, and apache (happily misconfigured) responds with an HTTP response telling the client the response came from barney.rhombus.net.

In that case your cookies WILL NOT WORK. Netscape or IE will figure that the cookie is intended for www.rhombus.net and the next time you ask for a page netscape will try to go to barney.rhombus.net, and so it won't send back the cookie, so no cookie value! Or alternatively your "path" parameter for the cookie may be specifying a domain that isn't the one apache is set up to respond as, results are the same.

In framesets this gets especially ugly. Browsers often don't seem to grok where content is really coming from. Telnetting to port 80 is highly useful sometimes...


In reply to RE: Fetching cookies. by Anonymous Monk
in thread Fetching cookies. by the_0ne

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.