| |||||||
|
|
Click here to download plain text source code.
# subroutine name: cookie # Returns cookie string for output to browser # Input: # $name - cookie name # $value - cookie value # $expires - expiration date or time increment # (understands also time offset # "12345s" - seconds # "1234h" - hours # "122d" - days # "12w" - weeks # "14m" - months # "1.5y" - year # $path - cookie path # $domain - cookie domain # $secure - secure cookie (true/false) sub cookie { my ($name, $value, $expires, $path, $domain, $secure) = @_; my $expires_date; %time_unit = ( s => 1, h => 3600, d => 86400, w => 86400*7, m => 86400*30, y => 86400*365, ); if ($expires =~ m/^(-?\d*?\.?\d+)(s|h|d|w|m|y)$/i) { $expires_date = &format_gmtdatetime(time + $1*$time_unit{lc($2)}); } else { $expires_date = $expires; } ($name, $value) = (&escape($name), &escape($value)); $secure=$secure?' secure':''; return "Set-Cookie: $name=$value; expires=$expires_date".($path?"; path\=$path":"").($domain?"; domain\=$domain":"")."$secure\n"; } |
|||||||||||||||||||||
| Copyright © 1999-2007 Atomicsoft Ltd. All Rights Reserved. | ||