Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Cookies with out milk.

by Snowdog (Sexton)
on Aug 08, 2000 at 02:44 UTC ( [id://26683]=perlquestion: print w/replies, xml ) Need Help??

Snowdog has asked for the wisdom of the Perl Monks concerning the following question:

I have consulted many tombs and artifacts of perl wisdom and yet knowledge escapes me. I am looking to place cookies with out using a module. It is not that I do not want to use a module Lincoln's would be fine. I can not. The server is controlled by nasty people who do not believe in modules or hobbits for that matter. SO if any one can point me to a reference then I would be ever so great full. I have tried every oreilly there is and a few non oreillys. If I missed it I will admit openly to stupidity. Well I will do that anyway. Thanks in advance.

Gandalf tea Wednesday.

Replies are listed 'Best First'.
Re: Cookies with out milk.
by tiny (Beadle) on Aug 08, 2000 at 05:14 UTC
    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"; } }
      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!
RE: Cookies with out milk.
by kirbyk (Friar) on Aug 08, 2000 at 02:51 UTC
Re: Cookies with out milk.
by BlueLines (Hermit) on Aug 08, 2000 at 02:51 UTC
    argh. trying to hand roll cookie code is tough. Why not just compile whatever module you need, stick it in your home directory, and do:
    $foo='/path/to/my/module'; use lib $foo;

    Update: merlyn pointed out below that this won't work. It should be:

    use lib '/path/to/my/modules';

    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.
      And thus spoke bluelines:
      $foo='/path/to/my/module'; use lib $foo;
      Which won't work, because the use will be at compile time, but the setting of $foo will not happen until runtime. {sigh}.

      Either put the assignment inside a BEGIN, or just use lib '/path/to/my/module';

      -- Randal L. Schwartz, Perl hacker

        argh. stupid compile time.

        BlueLines

        Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.
      I like the Idea but the Server admins would not. Not that I would have to tell them.
Re: Cookies with out milk.
by Adam (Vicar) on Aug 08, 2000 at 02:52 UTC
    You are not stupid.

    I would read the contents of CGI::Cookies.pm and see what you can scrounge from that code. You might also consider adding a subdirectory to the cgi-bin you are using and install libraries there. Then just add that directory to @INC inside a begin block in your script. (or on the #! line). There are many ways to get around evil sysops.

Re: Cookies with out milk.
by nardo (Friar) on Aug 08, 2000 at 02:56 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-16 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found