Script Archive has a good library I use, along with good examples I was able to read through and understand. You can use his library to perform function calls for all your cookie management.

Basically, whenever you set a cookie to a user, it has a name and a value. Whenever a user visits you domain, all cookies are passed to your server that were set by your domain.

So if you want to send a cookie, you call the function to set the expiration date at whatever you want, print your http header, and between the two end-of-lines of the header, call the setCookie function. The set function will take a name-value pair (as many as you want to pass) and sets those cookies onto the client.

To remove cookies, you'd do the same as above only set the date for some time in the past. Then it will delete cookies with those names off the client.

To get a cookie, you just call the getCookie function. That returns a true or false if the cookie exists. To get the actual value of the cookie, you would use the line $valueIwant = $Cookies{'cookieName'}; that way you can set multiple cookies to a client and get them.

Again, the README and counter example should help you work through it. Good luck.


In reply to Re: How do I use HTTP Cookies? by rawjoeshaw
in thread How do I use HTTP Cookies? by Spidy

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.