|
|
14.02.2006
[ Printer-friendly ] [ Send a cookie from a client ]
my $query = CGI->new;
# read cookie 'your_cookie_name':
my %cookie_val = $query->cookie(-name => 'your_cookie_name');
# Debug: foreach (keys %cookie_val) { Debug "----> $_: $cookie_val{$_}" }
print $query->header(-type=>'image/gif',
-nph=>1,
-status=>'402 Payment required',
-expires=>'+3d',
-cookie=>$cookie,
-Cost=>'$2.00');
The -nph parameter, if set to a true value, will issue the correct headers to work with a NPH (no-parse-header) script. This is important to use with certain servers, such as Microsoft Internet Explorer, which expect all their scripts to be NPH. expires When you specify an absolute or relative expiration interval with this parameter, some browsers and proxy servers will cache the script's output until the indicated expiration date. The following forms are all valid for the -expires field:
+30s 30 seconds from now
+10m ten minutes from now
+1h one hour from now
-1d yesterday (i.e. "ASAP!")
now immediately
+3M in three months
+10y in ten years time
Thursday, 25-Apr-1999 00:40:33 GMT at the indicated time & date
Store a cookie
my $cookie = $q->cookie (
-name => 'wtk_cust_logon',
-value => \%cookie_val,
-path => '/',
-expires => '+12h'
);
my $cookie_persist = $q->cookie (
-name => 'wtk_cust_logon_persist',
-value => \%cookie_val_persist,
-path => '/',
-expires => '+3M' # 3 months in the future
);
# store cookie(s)
print $q->header(-cookie => [$cookie, $cookie_persist]);
Delete a cookie
# delete cookie....
#
my $cookie = $q->cookie (
-name => 'wtk_cust_logon',
-value => '',
-path => '/',
-expires => '-1d'
);
print $q->header(-cookie => $cookie);
# default content-type text/html is set as well from now
Further References
| ||||||||||||||
copyright by reto - created with mytexi