in reply to Cookies with out milk.
###################################################################### +##### # 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 |