Here are set_cookie and get_cookie subs that I have used in the past. I stole these from something, but I don't remember what. Please feel free to correct them if anything is wrong with them.
###################################################################### +##### # Get_cookie - Gets all the cookies and returns them in a hash # Usage: my %cookie = &get_cookie; ###################################################################### +##### sub get_cookie { my @cstuff = @_; my ($cookie, $value, $char, %cookie); my @Cdec = ('\+', '\%3A\%3A', '\%3D', '\%2C', '\%25', '\%2B', '\%26' +,'\%3B'); my %Cdec = ('\+',' ','\%3A\%3A','::','\%3D','=','\%2C',',','\%25','% +','\%2B','+','\%26','&','\%3B',';'); if ($ENV{'HTTP_COOKIE'}) { foreach (split(/; /,$ENV{'HTTP_COOKIE'})) { ($cookie,$value) = split(/=/); foreach $char (@Cdec) { $cookie =~ s/$char/$Cdec{$char}/g; $value =~ s/$char/$Cdec{$char}/g; } $cookie{$cookie} = $value; } } return %cookie; } ###################################################################### +##### # set_cookie - Sets a cookie. # Usage : set_cookie('Name',"Value",?) ? = 0 or 1. 0 = temp, 1 = perma +nent ###################################################################### +##### sub set_cookie { my @cookie = @_; my ($cookie, $value, $type, $char); my @Cenc = ('\;','\&','\+','\%','\,','\=','\:\:','\s'); my %Cenc = ('\;','%3B','\&','%26','\+','%2B','\%','%25','\,','%2C',' +\=','%3D','\:\:','%3A%3A','\s','+'); my $header = ''; for (my $i = 0; $i <= $#cookie; $i = $i + 3) { ($cookie, $value, $type) = @cookie[$i .. $i+2]; foreach $char (@Cenc) { $cookie =~ s/$char/$Cenc{$char}/g; $value =~ s/$char/$Cenc{$char}/g; } $header = 'Set-Cookie: ' . $cookie . '=' . $value . ';'; if ($type == 1) { $header .= ' expires=Friday, 31-Dec-2010 00:00:00 GMT; path=/'; } print "$header\n"; } }

In reply to Re: Cookies with out milk. by tiny
in thread Cookies with out milk. by Snowdog

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.