Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Cookies with out milk.

by tiny (Beadle)
on Aug 08, 2000 at 05:14 UTC ( [id://26718]=note: print w/replies, xml ) Need Help??


in reply to Cookies with out milk.

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"; } }

Replies are listed 'Best First'.
(bbq) RE: Re: Cookies with out milk.
by BBQ (Curate) on Aug 09, 2000 at 00:48 UTC
    I've seen those on cookie-lib.pl (inspired by cgi-lib.pl). I might still have a copy around here somewhere, if anyone wants to check it out I can look for it on tape. Just /msg me in the chatterbox and I'll put a link here or something.

    #!/home/bbq/bin/perl
    # Trust no1!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://26718]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-25 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found