in reply to Re: Cookies without using CGI.pm
in thread Cookies without using CGI.pm

I can understand why you might need this, since some webhosters don't even provide CGI.pm. You can retrieve most cookies with a function like this.
sub GetCookies { %decode = ('\+'=>' ','\%3A\%3A'=>'::','\%26'=>'&','\%3D'=>'=', '\%2C'=>',','\%3B'=>';','\%2B'=>'+','\%25'=>'%'); my %Cookies = (); foreach (split(/; /,$ENV{'HTTP_COOKIE'})) { my ($cookie,$value) = split(/=/); foreach $ch ('\+','\%3A\%3A','\%26','\%3D','\%2C','\%3B','\%2B','\ +%25') { $cookie =~ s/$ch/$decode{$ch}/g; $value =~ s/$ch/$decode{$ch}/g; } $Cookies{$cookie} = $value; } return %Cookies; }
where the Cookies hash returned contains the cookies
----
FightLiteracy.com
http://www.fightliteracy.com

Replies are listed 'Best First'.
Re: Retrieving cookies without CGI.pm
by Beatnik (Parson) on Jul 25, 2001 at 00:09 UTC
    When some hosts explicitly remove CGI.pm from the core package, they're plain stupid...
    Parsing cookies is pretty similar to parsing forms, as it can be broken quite easily if you're not carefull. I'm confident your code is flawded in one way or another (altho I'm not gonna chase the hole). Check merlyn's No excuses about not using CGI.pm. I confess that most of my older CGI code didn't use CGI.pm for that kinda stuff, but now I've payed my sin.

    Maybe I should do a use CGI; #damnit! bat too...

    Needless to say I know how to parse cookies manually, since I set it manually in my original node :))

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.