Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cookies...mmmm...tasty! 1

Status
Not open for further replies.

simanek

Programmer
Joined
Jan 19, 2001
Messages
137
Location
US
Does anyone know or have a method that sets a cookie? I've been looking through the HTTP module in my perl nutshell book and it is about as clear as mud. I'll also be needing a request cookie method if anyone would care to explain that as well. I would actually prefer to stay away from the modules but beggars can't be choosers =) Thanks.

Mike
 
the CGI module should be able to do exactly what you want and fairly simply at that. cookies have to be set in the header of a page, so first you make the cookie and then you print it into the header. cookie requests should also be equally easy. here's an adaptation of stuff i found in the CGI docs:[tt]
my $query = new CGI;
my $oatmeal =
$query->cookie(-name=>'sessionID',
-value=>'xyzzy',
-expires=>'+1h',
-path=>'htdocs/database',
-domain=>'.domain.org',
-secure=>1);

print $query->header(-cookie=>$oatmeal);[/tt]

then, to retrieve a cookie, use cookie() with the only argument being the name of the cookie you want to retrieve (my %retrieved = $query->cookie("sessionID");). note that you can call this in array context and it will return an already parsed hash. the CGI module really is the best way to deal with html generation until you learn the underworkings of all that stuff (which is tons of fun - just read through the CGI module's source code ^_^ ).
HTH "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top