costas has asked for the wisdom of the Perl Monks concerning the following question:
sub set_cookie <br> { <br> my ($expires,$domain,$path,$secure,$cookie) = @_; <br> my(@days) = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");<br> my(@months) = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Se +p","Oct","Nov","Dec");<br> my($seconds,$min,$hour,$mday,$mon,$year,$wday) = gmtime($expires) +if ($expires > 0); #get date info if expiration set.<br> $seconds = "0" . $seconds if $seconds < 10; # formatting of date v +ariables<br> $min = "0" . $min if $min < 10; <br> $hour = "0" . $hour if $hour < 10; <br> my(@secure) = ("","secure"); # add security to the cookie if defin +ed. I'm not too sure how this works.<Br> if (! defined $expires) <Br> { <br> $expires = " expires\=Fri, 31-Dec-1999 00:00:00 GMT;"; <br> } # if expiration not set, expire at 12/31/1999 elsif ($expires == -1) <br> { <br> $expires = ""; <Br> } <br> else <br> { <br> $year += 1900; <br> $expires = "expires\=$days[$wday], $mday-$months[$mon]-$year $ +hour:$min:$seconds GMT; "; <br> }<br> if (! defined $domain) { $domain = $ENV{'SERVER_NAME'}; } #set d +omain of cookie. <br> if (! defined $path) { $path = "/"; } #set default path = "/"<br +> if (! defined $secure) { $secure = "0"; }<br><br> my $key;<br> foreach $key (keys %$cookie) <br> {<br><br> $cookie->{$key} =~ s/ /+/g; <br><br> print "Set-Cookie: $key\=$cookie->{$key}; expires=$expires; path=$ +path; domain=$domain \n\n"; <br><br> }<br><br> }<br>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Cant create a cookie! Please help
by Hot Pastrami (Monk) on Mar 22, 2001 at 00:07 UTC | |
|
Re: Cant create a cookie! Please help
by fpi (Monk) on Mar 22, 2001 at 00:22 UTC | |
|
Re: Cant create a cookie! Please help
by dvergin (Monsignor) on Mar 22, 2001 at 00:42 UTC | |
|
Re: Cant create a cookie! Please help
by Hero Zzyzzx (Curate) on Mar 22, 2001 at 23:42 UTC |