Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Multiple cookies in Catalyst, one longlasting and one session cookie

by martell (Hermit)
on Aug 27, 2020 at 19:33 UTC ( [id://11121133]=note: print w/replies, xml ) Need Help??


in reply to Multiple cookies in Catalyst, one longlasting and one session cookie

Responding to my own post because i've found a solution for this problem. It is actually straightforward:

Set a extra cookie by adding in your function:

$c->response->cookies->{'cookie_consent'} = { 'name' => 'cookie_consent', 'value' => '1', 'expires' => '+3M', 'max-age' => '+3M', 'domain' => 'yoursite', 'path' => '/', 'secure' => 0, 'samesite' => 'Lax', };

This will automatically add a cookie when the response is send.

You can test for the presence of a cookie by testing if the request has a cookie with the given name:

my $consent_cookie = $c->request->cookies->{'cookie_consent'};

If the value is set, the cookie exists. You can use the value to record the type of consent the user is given. It is now up to you to react appropriately on the presence or absence of the cookie.

Hopes this help other. I've been looking for the answer quite some time and had given up. Found the answer after searching for a different problem.

Kind regards

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11121133]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-05-27 22:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found