Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

cookie using cgi.pm

by csorensen (Beadle)
on Jun 29, 2000 at 23:56 UTC ( [id://20485]=CUFP: print w/replies, xml ) Need Help??

I read Lincoln Stein's excellent book on CGI.pm (the module he wrote). After reading the book I still had a hard time writing a cookie. For some reason the perl'ish way to set a cookie didn't work. In fact I see questions from people having the exact same problem.. so .. here's my solution (very short and simple)
#!/usr/bin/perl -w use CGI qw/:standard/; $the_cookie = cookie( -name=>'ident', -value=>somevalue); print "Set-Cookie: $the_cookie\n"; # NOTE: you cannot set the cookie and define it all on one line # you MUST create the cookie first .. then set it with a print stateme +nt

Replies are listed 'Best First'.
RE: cookie using cgi.pm
by Anonymous Monk on Jun 30, 2000 at 21:58 UTC
    why wouldn't you be able to create the cookie, and display it all on one line.. ?? There is no reason why this wouldn't work: print "Set-Cookie: ", cookie(-name=>'login',-value=>'bliz'), "\n"; But, to go one more step.. you are using the CGI package, let it handle the work of the headers... print header( -type => 'text/html', -cookie => cookie(-name=>'ident',-value=>'eatit200') );
      actually .. setting the cookie and defining it all on the same line has never worked for me ..
      that's why I wrote the cookie this way .. I have tried both of the methods you suggested (they are what I meant by a more perl'ish way) but they didn't work.

        they both worked fine for me?!? I tested them before posting them, and don't see a problem with them... ?!? Just for a cut and paste example,
        #!/usr/bin/perl -w use strict; use CGI qw/:standard/; print header( -type => 'text/plain', -cookie => cookie( -name=>'ident', -value=>'eatit200') ); print <<END_BLOCK; Eat it 200 my friend! Your cookie is now set! END_BLOCK 1;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-16 23:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found