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!

Cookies

Status
Not open for further replies.

straitwicked

Programmer
Feb 1, 2001
1
US
I have a perl script with a variable noerror. When noerror=0 I want a cookie to be set that will expire 90 days after being written. Can anyone tell me how to do this or point me in the right direction to figure out how to do it?
Any help is appreciated...

Thanks
 
This is an example of some code which looks to see if a cookie exists. If yes, then modify it. If no, then create it. As you repeatedly hit this code, you should be able to watch a cookie on your system swap its value from null to '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;


'hope this helps


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

Part and Inventory Search

Sponsor

Back
Top