Print to STDOUT the HTTP "Set-Cookie" header. That's the do-it-yourself way to set a cookie. The cookie header format is as such:
Set-Cookie: $name=$value; date=$cur_date; expires=$expires_date; path=$path; domain=$domain

$name is the name you want for your cookie,
$value is the string to be stored in the cookie,
$cur_date is date/time as of when the cookie was set, (format below)
$expires_date is the date when the cookie will expire (same format as $cur_date)
$path is the path on your website where the cookie will be valid (ex. "/cgi-bin"),
$domain is the domain where your cookie will be valid (ex. "www.hoobajub.com" or ".hoobajub.com"),
The date format is the following: "Wed, 5 Jan 2000 13:49:23 -0500" The catch with cookies is that they are not immediately available to your CGI programs once you set them. You'll have to redirect the browser once you've set the cookie. I.e. Customer fills out form and submits -> your program processes date, prints cookie header and redirect header -> browser goes to redirect page -> your cgi can now read the cookie. The other way to do it is use CGI.pm. Import that and you'll have the cookie() function. Called with a single argument (the name of the cookie you want to read) it returns as a scalar the value of the cookie. Check out Lincoln Stein's book "Official Guide to Programming with CGI.pm" for a detailed explanation of that package, or just read the source and use perldoc. HTH

In reply to Re: How can I get and set cookies? by Anonymous Monk
in thread How can I get and set cookies? by Anonymous Monk

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.