I think what you're saying is that you want to be able to access the cookie you are about to set in the current invocation???

If so, you need to set up a var to track this "cookie" (it's not a cookie before it's set, hence the quotes).

#!/usr/bin/perl use strict; use warnings; use CGI; my $q = CGI->new(); our $cookie = ''; if ( defined $q->cookie('cookiename') ) { $cookie = $q->cookie('cookiename') # validate cookie here based on whatever } elsif ($q->param('some_field_name') { # form submitted $cookie = 'whatever'; } else { # show the html form }
Then, whenever you print a page, ensure the cookie gets sent in the header.

I think understanding exactly what it is you don't understand is more the problem here than the actual problemn. perhaps you can explain it in a bit more detail?

.02

cLive ;-)

ps - you might want to look at the concept of using a "cookie jar" in your script. That way you can seamlessly ensure cookies get sent when you print headers. Here's a snippet....

# at beginning of script use CGI; our @cookie_jar = (); our $q = CGI->new(); # when you want to set a cookie push @cookies, $q->cookie(-name=>'sessionID', -value=>'xyzzy', -expires=>'+1h'); # when you print a page, instead of calling $q->header # use this instead print cookie_header; # which sends all cookies sub cookie_header { return $q->header(-cookie=>\@cookie_jar); } # if you're on mod_perl, you also need to empty # the cookie jar here, so amend sub cookie_header { my header = $q->header(-cookie=>\@cookie_jar); @cookie_jar = (); return $header; }
But, like I said, I'm grasping at straws here. I think if you could explain what you don't understand though, you'd probably find the answer yourself :)

The key to successful programming is to understand the questions. Once you've done that, the answers are trivial :)

.02

cLive ;-)


In reply to Re: How do they expect cookies to work (like this)?? by cLive ;-)
in thread How do they expect cookies to work (like this)?? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.