in reply to Cookies without using CGI.pm

Well, a way of rolling your own is tweaking the HTTP header and insert the Set-Cookie statement.
print "Content-type: text/html\n"; print "Set-Cookie: MyCookie=Something\n\n";
Basically, cookies are part of the HTTP header and have quite a few options... The code above sets a Session cookie (exists as long as the browser stays open). Expiring cookies need an extra expires option etc...
If you want the fancy stuff, stick to CGI.pm (it's installed by default).

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

Replies are listed 'Best First'.
Retrieving cookies without CGI.pm
by fightliteracy (Acolyte) on Jul 24, 2001 at 19:51 UTC
    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
      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.