in reply to How do they expect cookies to work (like this)??
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).
Then, whenever you print a page, ensure the cookie gets sent in the header.#!/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 }
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....
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 :)# 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; }
The key to successful programming is to understand the questions. Once you've done that, the answers are trivial :)
.02
cLive ;-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How do they expect cookies to work (like this)??
by Anonymous Monk on Oct 01, 2003 at 20:52 UTC | |
by cLive ;-) (Prior) on Oct 02, 2003 at 18:32 UTC |