Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

cookie using

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 (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', 

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

Replies are listed 'Best First'.
RE: cookie using
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://20485]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-02-25 18:24 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (314 votes). Check out past polls.