summaryrefslogtreecommitdiff
path: root/lib/cookies.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cookies.pm')
-rw-r--r--lib/cookies.pm55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/cookies.pm b/lib/cookies.pm
new file mode 100644
index 0000000..559e80a
--- /dev/null
+++ b/lib/cookies.pm
@@ -0,0 +1,55 @@
+# &setCookie("fuckface", "j1zzm0p");
+
+our $cookie_reset = "Friday, 31-Dec-1999 11:59:59 GMT";
+our $cookie_forever = "Friday, 21-Dec-2069 12:28:49 GMT";
+
+# our $cookies = getCookies() if ($ENV{'HTTP_COOKIE'});
+# store cookies in %$cookies
+
+sub setCookie
+ {
+ # end a set-cookie header with the word secure and the cookie will
+ # only be sent through secure connections
+
+ my ($args) = @_;
+ my $name = $args->{name} || undef;
+ my $value = $args->{value} || undef;
+ my $path = $args->{path} || undef;
+ my $domain = $args->{domain} || undef;
+
+# my ($name, $value, $path, $domain) = @_;
+ my $date;
+
+ if (!$value)
+ { $date = $cookie_reset; }
+ elsif (exists($args->{nologout}) && $args->{nologout} == 1)
+ { $date = $cookie_forever; }
+ else
+ { $date = 0; }
+
+ print "Set-Cookie: ";
+ print $name, "=", $value, "; ";
+ if ($date) { print "expires=$date; "; }
+# print "path=", $path, "; domain=", $domain, "; secure\n";
+ print "path=", $path, "; domain=", $domain, "\n";
+ }
+
+
+# cookies are seperated by a semicolon and a space, this will split
+# them and return a hash of cookies
+
+sub getCookies
+ {
+ my (@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'});
+ my %cookies;
+
+ foreach(@rawCookies)
+ {
+ my ($key, $val) = split (/=/,$_);
+ $cookies{$key} = $val;
+ }
+
+ return \%cookies;
+ }
+
+1;