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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting and reading cookies with Perl?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm having trouble setting and reading cookies with a Perl script. I was wondering if anyone has a "generic" perl script that will help me accomplish my goal.

Thanks
 
Look on for the perl::Cooke module, or something like that.

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
If cookies are enabled in your browser, the following should set a cookie named 'cookThis' and with each hit of this code, the value of the cookie should swap back and forth between null and 'Some Cookie value here'.



#!/usr/local/bin/perl
use CGI;
$query = new CGI;
$thisCGI = $query->url();

# try to read the cookie via the CGI.pm method
$cookThis = $query->cookie(-name=>'cookThis');

# If the cookie exists, edit it's values.
# else, create it's values.
if ($cookThis)
{
$cookie = $query->cookie(-name=>"cookThis",
-value=>'',
-expires=>"+1h");
}
else
{
$cookie = $query->cookie(-name=>"cookThis",
-value=>"Some Cookie value here",
-expires=>"+1h");
}

# print the cookie in the header.
print $query->header(-cookie=>$cookie);
print &quot;<BR>CookThis is $cookThis<BR>&quot;;
print $query->start_html(-title=>&quot;cook this&quot;);
print $query ->start_multipart_form('POST',&quot;$thisCGI&quot;);
print '<BR>',$query->submit('doWhat','cook');
print $query->end_form;
print $query->end_html;


Just ask if you have questions....
HTH


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top