Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

cookie using cgi.pm

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

Description: 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

Comment on cookie using cgi.pm
Download Code
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;

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-09-21 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls