added on local at 2026-07-01 12:34:30
| 1 | package MODS::ReadSetCookie; | |
| 2 | ||
| 3 | use strict; | |
| 4 | use CGI; | |
| 5 | my $query = new CGI; | |
| 6 | ||
| 7 | #Load the random alpha numeric code generator | |
| 8 | use MODS::RandCode; | |
| 9 | my $randcode = new MODS::RandCode; | |
| 10 | ||
| 11 | sub new { | |
| 12 | my($class, %args) = @_; | |
| 13 | my $self = bless({}, $class); | |
| 14 | ||
| 15 | return $self; | |
| 16 | } | |
| 17 | ||
| 18 | ||
| 19 | sub read_cookie{ | |
| 20 | my($self, $name) = @_; | |
| 21 | ||
| 22 | #Read the cookie and look for an existing session that is running | |
| 23 | my $session = $query->cookie(-name=>"$name"); | |
| 24 | #-------------------------------------------------------------- | |
| 25 | ||
| 26 | return $session; | |
| 27 | } | |
| 28 | ||
| 29 | ||
| 30 | sub set_cookie{ | |
| 31 | my($self, $name) = @_; | |
| 32 | ||
| 33 | my $session1 = $randcode->generate(20) . time() . $randcode->generate(20); | |
| 34 | my $session2 = $randcode->generate(20) . time() . $randcode->generate(20); | |
| 35 | my $session = "$session1" . '---' . "$session2"; | |
| 36 | ||
| 37 | #Set the cookie session since none was found. Domain omitted so the | |
| 38 | #cookie scopes to whichever vhost served the request (works for | |
| 39 | #webstls.com, www.webstls.com, and any subdomain on the same host). | |
| 40 | my $cookie = $query->cookie(-name=>"$name", -value=>"$session", -expires => '+5M', -secure => 1, -httponly => 1, -samesite => 'Lax'); | |
| 41 | print $query->header(-cookie=>$cookie); | |
| 42 | #-------------------------------------------------------------- | |
| 43 | ||
| 44 | return $session; | |
| 45 | } | |
| 46 | ||
| 47 | 1; |